Source code to send clicks (Minimized)

09/09/2008 13:03 clipper#1
Well let an example of some functions in VB6 to send clicks and pfs to the screen.
They work with the client miniminized or in background.

It is a way that I have not seen used in the examples in the forum but I think it is the most effective.

Unfortunately not comment on the code but the idea is this:

Send messages BUTTONDOWN / BUTTONUP directly to the window handle control that contains the display or which contains buttons pf. not to the window pricipal Co

GetHandleControl search recursively controlid in the windows daughters hwnd parameter and returns the handle of it.

You can find the controlid with WinSpy or similar and/or traveling checks at the function GetHandleControl modified to get extra info on the controls.

This work for spanish client. I suppose the identifiers of objects will be the same in different clients languages....

sry for my bad (or null) English :D

Code:
'w. api
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Const GW_CHILD = 5
Public Const GW_HWNDNEXT = 2
Public Const WM_LBUTTONDOWN As Long = &H201
Public Const WM_LBUTTONUP As Long = &H202
Public Const WM_LBUTTONDBLCLK As Long = &H203
Public Const WM_RBUTTONDOWN As Long = &H204
Public Const WM_RBUTTONUP As Long = &H205
Public Const WM_RBUTTONDBLCLK As Long = &H206
 
'Publics variables
Public d_hWndScreen As Long
Public d_hWndPFs As Long
 
'put in load event or initzialize funcion
'hwnd is co window
d_hWndPFs = GetHandleControl(hwnd, &H3FD)
d_hWndScreen = GetHandleParentControl(hwnd, &H3E8)
 
'Funcions to use
Public Sub SendClick(nX As Integer, nY As Integer, Optional nBoton As Integer = vbLeftButton)
Dim lTarget As Long 
If nX < 0 Or nX > 1024 Or nY < 0 Or nY > 768 Then Exit Sub
lTarget = MakeDWord(nX, nY) 
Select Case nBoton
Case vbLeftButton:
SendMessage d_hWndScreen, WM_LBUTTONDOWN, 1&, ByVal lTarget
SendMessage d_hWndScreen, WM_LBUTTONUP, 1&, ByVal lTarget
Case vbRightButton:
SendMessage d_hWndScreen, WM_RBUTTONDOWN, 1&, ByVal lTarget
SendMessage d_hWndScreen, WM_RBUTTONUP, 1&, ByVal lTarget
End Select
End Sub
 
Public Sub SendPF(Optional sPF As String = "PF1")
Dim lTarget As Long
Dim nPF As Integer 
If Len(sPF) < 3 Then Exit Sub
nPF = CInt(Right(sPF, Len(sPF) - 2))
If nPF = 0 Then Exit Sub 
lTarget = MakeDWord(20 + ((nPF - 1) * 40), 20)
SendMessage d_hWndPFs, WM_RBUTTONDOWN, 1&, ByVal lTarget
SendMessage d_hWndPFs, WM_RBUTTONUP, 1&, ByVal lTarget
End Sub
 
'Functions to internal work 
Private Function MakeDWord(ByVal LoWord As Integer, ByVal HiWord As Integer) As Long
MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
End Function
 
Private Function GetHandleParentControl(hwnd As Long, lControlID As Long) As Long 
GetHandleParentControl = GetParent(GetHandleControl(hwnd, lControlID))
End Function
 
Private Function GetHandleControl(hwnd As Long, lControlID As Long) As Long
Dim lID As Long
Dim hWndChild As Long
lID = GetWindowLong(hwnd, GWL_ID)
If lID = lControlID Then
GetHandleControl = hwnd
Else
hWndChild = GetWindow(hwnd, GW_CHILD)
Do While hWndChild <> 0 And GetHandleControl = 0
lID = GetWindowLong(hWndChild, GWL_ID)
If lID = lControlID Then
GetHandleControl = hWndChild
Else
If GetWindow(hWndChild, GW_CHILD) <> 0 Then
GetHandleControl = GetHandleControl(hWndChild, lControlID)
End If
End If
hWndChild = GetWindow(hWndChild, GW_HWNDNEXT)
Loop
End If
End Function