依次发送WM_LBUTTONDOWN和WM_LBUTTONUP消息即可(发送消息时lParam参数就指定了鼠标点击的位置) lParam: The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area. The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area
//PostMessage(hWnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(x,y)); 怎么转换为VB中的语句? 这样: Function MakeDWord(LoWord as Integer, HiWord as Integer) as Long MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&) End Function 调用: PostMessage(hWnd,WM_LBUTTONDOWN,MK_LBUTTON,MakeDWord(x,y))
【函数】
mouse_event【操作系统】
Win9X:Yes
WinNT:Yes【声明】
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)As Boolean 【说明】 模拟一次鼠标事件 【返回值】
【其它】 进行相对运动的时候,由SystemParametersInfo函数规定的系统鼠标轨迹速度会应用于鼠标运行的速度【参数表】
dwFlags -------- Long,下述标志的一个组合
MOUSEEVENTF_ABSOLUTE dx和dy指定鼠标坐标系统中的一个绝对位置。在鼠标坐标系统中,屏幕在水平和垂直方向上均匀分割成65535×65535个单元 - MOUSEEVENTF_MOVE
移动鼠标
MOUSEEVENTF_LEFTDOWN
模拟鼠标左键按下
MOUSEEVENTF_LEFTUP
模拟鼠标左键抬起
MOUSEEVENTF_RIGHTDOWN
模拟鼠标右键按下
MOUSEEVENTF_RIGHTUP
模拟鼠标右键按下
MOUSEEVENTF_MIDDLEDOWN
模拟鼠标中键按下
MOUSEEVENTF_MIDDLEUP
模拟鼠标中键按下
dx
Long,根据是否指定了MOUSEEVENTF_ABSOLUTE标志,指定水平方向的绝对位置或相对运动 dy ------------- Long,根据是否指定了MOUSEEVENTF_ABSOLUTE标志,指定垂直方向的绝对位置或相对运动 cButtons ------- Long,未使用 dwExtraInfo ---- Long,通常未用的一个值。用GetMessageExtraInfo函数可取得这个值。可用的值取决于特定的驱动程序
POINT pt;
GetCursorPos(&pt);
mouse_event(MOUSEEVENTF_LBUTTONDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LBUTTONUP,0,0,0,0);
SetCursorPos(pt.x,pt.y);
大体上就这个思路吧,很久没有用vb了,只能用vc的语法了,抱歉。
除此之外还有的方法就是
PostMessage到窗口一条WM_LBUTTONDOWN的消息
不过我以前用的时候好像鼠标会自己移动过去的,并且没有上面的那个方法好。
lParam:
The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area. The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area
lParam 的LOWORD是X
HIWORD是Y
在VC中只这样写的
PostMessage(hWnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(x,y));
怎么转换为VB中的语句?
http://vbclass.8u8.com/jishu/yaokong.htm
怎么转换为VB中的语句?
这样:
Function MakeDWord(LoWord as Integer, HiWord as Integer) as Long
MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
End Function
调用:
PostMessage(hWnd,WM_LBUTTONDOWN,MK_LBUTTON,MakeDWord(x,y))