Click to See Complete Forum and Search --> : Send a mouse click to a certain position within a child window
rossim
Feb 13th, 2001, 11:11 AM
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)
Use this MakeDWord function.
Public Function MakeDWord(ByVal LoWord As Integer, ByVal HiWord As Integer) As Long
MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
End Function
rossim
Feb 13th, 2001, 02:31 PM
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
Lord Orwell
Feb 14th, 2001, 01:44 AM
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.
rossim
Feb 14th, 2001, 06:27 AM
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.
Scott Healey
Feb 15th, 2001, 10:29 AM
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
Lord Orwell
Feb 16th, 2001, 02:31 AM
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)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.