PDA

View Full Version : Code snippet: Click to window at client coordinates



Petr Schreiber
18-01-2015, 12:56
Every man reaches a point in his life, when he needs to... click on specified point in window!

Here is my proposal for enhancing UI module with such a functionality:


' -- Win32
Begin Const
%MouseEventF_LeftDown = &H2
%MouseEventF_LeftUp = &H4
End Const
Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

' -- Functions
Function Win_ClickAt( hWnd As DWord, x As Long, y As Long )

Win_SetForeground(hWnd)

Dim clickPosition As POINTAPI
clickPosition.x = x
clickPosition.y = y

Win_ClientToScreen(hWnd, clickPosition)
Win_SetCursorPos(clickPosition.x, clickPosition.y)
mouse_event(%MouseEventF_LeftDown, 0, 0, 0, 0)
mouse_event(%MouseEventF_LeftUp, 0, 0, 0, 0)

End Function



Petr

mike lobanovsky
19-01-2015, 14:21
Every man reaches a point in his life, when he needs to... click on specified point in window!


http://christhehumanist.files.wordpress.com/2011/12/jesus-guy.jpg