-
Is this the way how to click the "OK" or any button from another application?
Thanks for helping!!!
Code:
Option Explicit
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function Findwindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wparam As Long, lparam As Any) As Long
'Private Declare Function SendMessageByNum Lib "user32" Alias "SendMessageA" (ByVal hWnd%, ByVal wMsg%, ByVal wparam%, ByVal lparam&)
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Sub Timer1_Timer()
Dim lng_Dialog As Long
Dim lng_Button As Long
lng_Dialog = Findwindow("#32770", vbNullString)
lng_Button = FindWindowEx(lng_Dialog, 0&, "Button", vbNullString)
Call Click(lng_Button)
End Sub
Sub Click(lng_Handle As Long)
DoEvents
Dim lng_Response As Long
lng_Response = SendMessage(lng_Handle, WM_LBUTTONDOWN, 0, 0&)
lng_Response = SendMessage(lng_Handle, WM_LBUTTONUP, 0, 0&)
End Sub
-
Probably, try it and see :)
-
I can see the button getting click but it is not closing the message box. The other way to close a message box is using the constant - wm_close. I just like to know why the code made the OK button click but it won't close the message box.
-
Nitro - did you ever find out why clicking the OK button did not fire the close event on the external applications message box???
I am also trying to click an external applications button and although I can see the button being clicked, the click event does not appear to be fired off. (Unfortunately, I cannot get away with using WM_CLOSE, becuase I need the event to take place.)
Any help would be greatly appreciated.
-
Sorry Ishamel!
I am still stuck and don't understand why. Someone out there have any ideas?
The codes above clicks a foreign application's button, but it doesn't do anthing afterward. We can actually see the "OK" button of the message box gets click.
[Edited by Nitro on 06-13-2000 at 03:46 PM]
-
Hi Nitro,
question:
Is the window the Active window when the button is clicked?
If not try to make it so and then retry.
DocZaf
{;->
course i may be wrong
-
Thanks Zaf!
It is actually a messagebox. I made it click OK but it won't close the message box. The other alternative is wm_close.
Thanks buddy.