Results 1 to 7 of 7

Thread: Send a mouse click to a certain position within a child window

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    NJ
    Posts
    148
    I am trying to send a left mouse click to a certain position within a child window. I have the handle of the child window, but cannot get the sendmessage to work. Any ideas?

    Here is some of the code:

    [code]

    Type POINT_TYPE
    x As Long
    y As Long
    End Type

    Public Function MAKEWORD(ByVal bLow As Byte, ByVal bHigh As Byte) As Integer
    MAKEWORD = Val("&H" & Right("00" & Hex(bHigh), 2) & Right("00" & Hex(bLow), 2))
    End Function

    '--------------------------------------------------------------------

    strWindowTitle = "Find"

    AppActivate (strWindowTitle)

    Call HPause(0.5)

    lHwnd = FindWindow(vbNullString, strWindowTitle)

    lCwnd = FindWindowEx(lHwnd, 0&, ThunderRT6ListBox", vbNullString)
    lCwnd2 = FindWindowEx(lHwnd, lCwnd, "ThunderRT6ListBox", vbNullString)

    packed = MAKEWORD(112, 73)

    rc = PostMessage(lCwnd2, WM_LBUTTONDOWN, MK_LBUTTON, ByVal packed)
    DumEvents = DoEvents
    DumEvents = DoEvents
    rc = PostMessage(lCwnd2, WM_LBUTTONUP, MK_LBUTTON, ByVal packed)

  2. #2
    Guest
    Use this MakeDWord function.
    Code:
    Public Function MakeDWord(ByVal LoWord As Integer, ByVal HiWord As Integer) As Long
       MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
    End Function

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    NJ
    Posts
    148

    Cool

    I think I just answered my own question. Here is the code I used.

    [code]

    'Declares
    Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
    Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

    Type POINTAPI
    x As Long
    y As Long
    End Type

    Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
    Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
    Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
    Private Const MOUSEEVENTF_MOVE = &H1 ' move

    Dim P As POINTAPI

    '---------------------------------------------------------

    'Button

    P.x = 0
    P.y = 0

    strWindowTitle = "Find"

    AppActivate (strWindowTitle)

    lHwnd = FindWindow(vbNullString, strWindowTitle)
    lCwnd = FindWindowEx(lHwnd, 0&, "Afx:400000:b", vbNullString)

    'Get the postion of the hwnd
    ret = ClientToScreen(lCwnd, P)

    'Set where I want to click
    P.x = P.x + 211
    P.y = P.y + 50

    'Move cursor
    ret = SetCursorPos(P.x, P.y)

    'Click Mouse Button
    mouse_event MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, P.x, P.y, 0, 0

    [\code]

    I tried this code and it worked. If anyone knows of an easier way, please let me know.

    Thanks,

    Mike

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    hmm
    if you are trying to click a button on a form in another document, you simply need to get the handle of the button/listbox/etc, and send the button down and button up event to that child's message handler.
    (postmessage)

    Speaking of which, i used your method in an aol program. If anyone knows how to come up with the handle to the hearts, i'd love to hear it.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    NJ
    Posts
    148
    Thats what I tried at first. The only problem was that I had to click a certain position within a child window that did not have its own handle. The only problem with my code, is that if that postition I have to click moves, I will have to recompile the app with the correct parameters.

  6. #6
    New Member
    Join Date
    Feb 2001
    Posts
    3

    Lightbulb

    i was thinking of an app that could click certain controls on a web page created with javascript. my problem is that the controls move depending what banner adds are displayed.

    it must be possible to get the coordinates of the control then send a mouse click to that coordinate.

    -scott healey

  7. #7
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    Why don't you give up. It is much easier to send tabs and then a space to click. One tab for each object. Until you get the right one. (i had the same problem)
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

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