使用SendMessage 模拟鼠标点击 [问题点数:25分,结帖人Game4s]
| |
楼主 发表于: 2008-11-16 23:42:20 | |
已知目标窗口的句柄 hWnd
如何根据自定义的X,Y坐标值使用SendMessage向目标窗口发送鼠标点击指令? 请给出实例代码.非常感谢 | |
回复次数:8 |
| |
#1 得分:0 回复于: 2008-11-17 00:24:02 | |
SendMessage(hWnd,WM_LMOUSEDOWN,x,y);
| |
| |
#2 得分:22 回复于: 2008-11-17 07:59:48 | |
SendMessage(hWnd, WM_LBUTTONDOWN, MK_LBUTTON, makelparam(x,y));
| |
| |
#3 得分:0 回复于: 2008-11-17 08:00:35 | |
SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, makelparam(x,y));
| |
| |
#4 得分:1 回复于: 2008-11-17 08:24:01 | |
用RegisterwindowMessage注冊唯一窗口标识
send方 var Form1: TForm1; UserMessage:UINT; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin SendMessage(FindWindow('TForm1','RegisterMessage Get Example'),UserMessage,0,0); //'RegisterMessage Get Example'接受窗口名字caption end; procedure TForm1.FormCreate(Sender: TObject); begin UserMessage:=RegisterwindowMessage('System Wide User Defined Message'); end; get方: var Form1: TForm1; UserMessage:UINT; implementation {$R *.dfm} procedure TForm1.DefaultHandler(var Msg); begin inherited DefaultHandler(Msg); if (TMessage(Msg).Msg=UserMessage) then begin button1.Click; end; end; procedure TForm1.FormCreate(Sender: TObject); begin UserMessage:=RegisterWindowMessage('System Wide User Defined Message'); end; procedure TForm1.Button1Click(Sender: TObject); begin showmessage('ok'); end; | |
| |
#5 得分:0 回复于: 2008-11-17 08:25:37 | |
SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, makelparam(x,y));
| |
| |
#6 得分:1 回复于: 2008-11-17 08:27:19 | |
GetCursorPos(m);是取鼠标位置。
WindowFromPoint(m)是取M坐标点处的句柄,在这里当然也就是鼠标的位置。 sendMessage(WindowFromPoint(m), WM_LBUTTONDOWN, 0, 0); SendMessage(WindowFromPoint(m), WM_LBUTTONUP, 0, 0); | |
| |
#7 得分:1 回复于: 2008-11-17 19:50:29 | |
用mouse_event 函数多好
| |
| |
#8 得分:0 回复于: 2008-11-17 19:51:32 | |
自己解决了。
其实关键就是lParam 的格式问题. 前面几位回答的MakeLParam 函数没有尝试过,自己用了个 StrToInt(#36+IntToHex(Y,4)+IntToHex(X,4))) 达到了预期效果。结贴给分了 |