Valhalla Legends Forums Archive | Visual Basic Programming | Simulating mouse clicks using SendMessage

AuthorMessageTime
laurion
I have been trying this for around 2 and a half hours now, to no avail. For whatever reason, the program I am sending the keys to ( Firefox ) isn't reacting. It is supposed to click one of those option box things. I am totally clueless as to why it won't work..  >:( I got it to work once, out of the blue, and it never worked again.

[code]
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 FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
 
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const GW_CHILD = 5

Private hWndParent As Long
Private hWndChild As Long
'-----------------------------------------------------------------------------'

Public Sub SendClick(lnghWND As Long, x As Long, y As Long)

    Dim iResult As Long
    Dim lParam As Long
   
    lParam = (y * &H10000) + x
    Debug.Print "lParam is: " & lParam & " || lnghWND is: " & lnghWND & " || x is: " & x & " || y is: " & y

    iResult = SendMessage(lnghWND, WM_LBUTTONDOWN, 0&, ByVal lParam)
    iResult = SendMessage(lnghWND, WM_LBUTTONUP, 0&, ByVal lParam)
   
End Sub
Private Sub Command2_Click()

    Debug.Print hWndChild
    Call SendClick(hWndChild, 296, 701)

End Sub

Private Sub Form_Load()

    hWndParent = FindWindow(vbNullString, "Index - Mozilla Firefox")
    hWndChild = GetWindow(hWndParent, GW_CHILD)
    Debug.Print "parent: " & hWndParent
    Debug.Print "child: " & hWndChild

End Sub
[/code]
I am always getting a correct parent/child value, so that isn't the problem. I am also positive that my X,Y coords are correct.

Any help is appreciated.
May 14, 2006, 4:21 PM
Topaz
I was working with Mozilla earlier, FindWindow("MozillaUIWindowClass", vbNullString) is the right one to use
May 14, 2006, 6:25 PM
laurion
Yea, I saw that in Spy++, however, the window handle is not my problem, I derive that fine [child and parent].

Edit: Heh, [code]
FindWindow("MozillaUIWindowClass", vbNullString)[/code] and my way both produce the same results. *shrug*
May 14, 2006, 6:35 PM
laurion
Ok, how about this: How would I go about clicking on a radio button that is in an .aspx page in FireFox?
May 15, 2006, 2:51 AM
Grok
[quote author=Tazo link=topic=14978.msg152447#msg152447 date=1147623674]

[code]
    Debug.Print "lParam is: " & lParam & " || lnghWND is: " & lnghWND & " || x is: " & x & " || y is: " & y

    iResult = SendMessage(lnghWND, WM_LBUTTONDOWN, 0&, ByVal lParam)
    iResult = SendMessage(lnghWND, WM_LBUTTONUP, 0&, ByVal lParam)
[/code]
I am always getting a correct parent/child value, so that isn't the problem. I am also positive that my X,Y coords are correct.

Any help is appreciated.

[/quote]
Check the value of iResult on both calls.  Further, get the window properties of the lnghWND including any text/caption to help you verify you really do have the correct window handle.

You could also watch the mouse-class messages using SPY++ specifically to those buttons, and click them manually see which which messages are firing.
May 15, 2006, 9:18 PM
Grok
[quote author=Tazo link=topic=14978.msg152476#msg152476 date=1147661493]
Ok, how about this: How would I go about clicking on a radio button that is in an .aspx page in FireFox?
[/quote]

BM_CLICK maybe.

BM_CLICK - simulate the user clicking a button.
BM_GETCHECK - retrieve the check state of a radio button or check box.
BM_SETCHECK - set the check state of a radio button or check box.
May 15, 2006, 9:25 PM
laurion
I resorted to using a WebBrowser control and then using the .Click command. Thanks anyways though..
May 16, 2006, 3:37 AM
JoeTheOdd
Gross. =p
May 16, 2006, 12:09 PM

Search