该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
接下来来研究下模拟鼠标
模拟鼠标的常数整理,如下:
WM_MOUSEFIRST 0x0200 //移动鼠标时发生
WM_MOUSEMOVE 0x0200 //移动鼠标时发生,同WM_MOUSEFIRST
WM_LBUTTONDOWN 0x0201 //按下鼠标左键
WM_LBUTTONUP 0x0202 //释放鼠标左键
WM_LBUTTONDBLCLK 0x0203 //双击鼠标左键
WM_RBUTTONDOWN 0x0204 //按下鼠标右键
WM_RBUTTONUP 0x0205 //释放鼠标右键
WM_RBUTTONDBLCLK 0x0206 //双击鼠标右键
WM_MBUTTONDOWN 0x0207 //按下鼠标中键
WM_MBUTTONUP 0x0208 //释放鼠标中键
WM_MBUTTONDBLCLK 0x0209 //双击鼠标中键
再看下参数,模拟鼠标时wParam应设为0了,而lParam应该为实际参数
下面是在按下按钮时用sendmessage画点的实例:
首先当然是新建一个窗体,画一个按钮(最好画到右下角),并输入以下代码
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_LBUTTONDOWN = &H201 '按下鼠标左键
Private Const WM_LBUTTONUP = &H202 '释放鼠标左键
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Sub Command1_Click() '单击按钮时就发送消息(画在(80,80)的地方)
Call Click(Me.hwnd, 80, 80)
Me.PSet (80, 80)
End Sub
Private Sub Form_Load()
DrawWidth = 3 '设置输出的线宽
Me.ScaleMode = vbPixels '以像素为单位,因为windows坐标通常以像素为单位的
End Sub
Private Function GetPoint_long(P As POINTAPI) As Long '由于sendmessage的坐标参数不是以XY直接带入的,需要特殊的计算,以下就是算法
GetPoint_long = P.X + P.Y * 65536
End Function
Private Sub Click(hwnd As Long, X As Long, Y As Long) '模拟单击
Dim p1 As POINTAPI
Dim p2 As Long '用于储存计算后的坐标
p1.X = X
p1.Y = Y
p2 = GetPoint_long(p1)
Call SendMessage(hwnd, WM_LBUTTONDOWN, 0, p2)
Call SendMessage(hwnd, WM_LBUTTONUP, 0, p2)
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) '如果是左键单击的话,就在指定画个点
If Button = 1 Then Me.PSet (X, Y)
End Sub
个人空间:http://hi.baidu.com/qjhirxklhlefvxr
转载请声明源处,谢谢