• Welcome to Valhalla Legends Archive.
 

Simulating mouse clicks using SendMessage

Started by Tazo, May 14, 2006, 11:21 AM

Previous topic - Next topic

Tazo

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.


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

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.

topaz

I was working with Mozilla earlier, FindWindow("MozillaUIWindowClass", vbNullString) is the right one to use
RLY...?

Tazo

#2
Yea, I saw that in Spy++, however, the window handle is not my problem, I derive that fine [child and parent].

Edit: Heh,
FindWindow("MozillaUIWindowClass", vbNullString)
and my way both produce the same results. *shrug*

Tazo

Ok, how about this: How would I go about clicking on a radio button that is in an .aspx page in FireFox?

Grok

Quote from: Tazo on May 14, 2006, 11:21 AM


    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)

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.

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.

Grok

Quote from: Tazo on May 14, 2006, 09:51 PM
Ok, how about this: How would I go about clicking on a radio button that is in an .aspx page in FireFox?

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.

Tazo

I resorted to using a WebBrowser control and then using the .Click command. Thanks anyways though..

Joe[x86]

Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.