Public Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Public Sub SendClick(lnghWND As Long, x As Long, y As Long)
Dim lngResult As Long
Dim lnglParam As Long
lnglParam = (y * &H10000) + x
lngResult = SendMessage(lnghWND, WM_LBUTTONDOWN, 0&, ByVal lnglParam)
lngResult = SendMessage(lnghWND, WM_LBUTTONUP, 0&, ByVal lnglParam)
End Sub
==================================================================
另外,不要忘了,把windows corrdinate system 设置为 pixels
有个例子吗,我好像很难试出一个正确的使用方法,还有,程序运行产生错误
compile error:
Only user-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions.
很难理解呀!
示例代码:
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)
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_ABSOLUTE = &H8000
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
Private Sub Command1_Click()
Dim a As Integer
Do
a = a + 1
If a = 3 Then GoTo proc_exit
'Simulate a mouseclick on the cursor's position
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0&, 0&, 0, 0
DoEvents
Loop
【VB声明】
Private 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)