如何发送鼠标左键点击消息?(200分)

P

Passion

Unregistered / Unconfirmed
GUEST, unregistred user!
知道一个应用程序窗体的HWND,如何使用SendMessage函数或者PostMessage函数<br>来模拟在该窗体上的X,Y处单击鼠标左键的效果?
 
procedure TForm1.Button2Click(Sender: TObject);<br>var<br>&nbsp; Wnd: HWND;<br>&nbsp; WinPos: TRect;<br>&nbsp; xy: TPoint;<br>begin<br><br>&nbsp; Wnd := FindWindow('TAppBuilder',nil); &nbsp;//找到Delphi IDE 的 handle<br>&nbsp; if Wnd &lt;&gt; 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; SetForegroundWindow(Wnd);<br>&nbsp; &nbsp; GetWindowRect(Wnd,WinPos);<br>&nbsp; &nbsp; xy.x := WinPos.Left + 10; &nbsp;//(10,10)是窗口内的相对位置。<br>&nbsp; &nbsp; xy.y := WinPos.Top + 10;<br>&nbsp; &nbsp; SetCursorPos(xy.x,xy.y);<br>&nbsp; &nbsp; Mouse_Event(MOUSEEVENTF_LEFTDown,xy.x,xy.y,0,0);<br>&nbsp; &nbsp; Mouse_Event(MOUSEEVENTF_LEFTUP, &nbsp;xy.x,xy.y,0,0);<br>&nbsp; end<br>&nbsp; else ShowMessage('window not found');<br><br>end;
 
谢了,我明天去试一试再给分。
 

Similar threads

I
回复
0
查看
559
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
490
import
I
D
回复
0
查看
2K
DelphiTeacher的专栏
D
顶部