Results 1 to 13 of 13

Thread: Problems simulating mouse clicks using SendMessage

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    15

    Angry Problems simulating mouse clicks using SendMessage

    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 click 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..

    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
    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.
    Last edited by Tazo; May 14th, 2006 at 01:54 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width