怎样向某个后台窗口的(x,y)发送点击鼠标的信息?(80分)

  • 主题发起人 主题发起人 iamphp
  • 开始时间 开始时间
I

iamphp

Unregistered / Unconfirmed
GUEST, unregistred user!
  向一个后台窗口的(x,y)发单击鼠标左键的信息,用<br>mouse_events是不行的。<br>&nbsp; &nbsp; 如何向后台窗口的(x,y)发单击鼠标左键的信息而不<br>影响前台窗口的工作???<br>
 
应该可以,我编了一个程序定时激活一个后台应用程序的窗口,然后点击该窗口的特定区域。下面仅是部分源程序,若觉有用,我可将全部文件打包发到你的信箱里!<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; ExtCtrls, StdCtrls;<br><br>type<br>&nbsp; TGetDot = class(TForm)<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; GetDot: TGetDot;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TGetDot.Timer1Timer(Sender: TObject);<br>var<br>&nbsp; &nbsp;hCurWindow,CurActiveWindow: HWnd; &nbsp;// 窗口句柄<br>&nbsp; &nbsp;WinText: array [0..255] of char;<br>&nbsp; &nbsp;WinCount:Integer;<br>begin<br>&nbsp; &nbsp; &nbsp;WinCount:=0;<br>&nbsp; &nbsp; &nbsp;CurActiveWindow:=GetActiveWindow();<br>&nbsp; &nbsp; &nbsp;hCurWindow := GetWindow(Handle, GW_HWNDFIRST);<br>&nbsp; &nbsp; &nbsp;// 获取第一个窗口的句柄<br>&nbsp;while hCurWindow &lt;&gt; 0 do<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;// 获取窗口的名称<br>&nbsp; &nbsp;if GetWindowText(hCurWindow, @WinText, 255)&gt;0 then<br>&nbsp; &nbsp; &nbsp; if ( WinText='民主湖聊天室 - Microsoft Internet Explorer') then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 激活该应用程序窗口,使其在屏幕最前面<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SendMessage(hCurWindow,WM_SYSCOMMAND,SC_MINIMIZE,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SendMessage(hCurWindow,WM_SYSCOMMAND,SC_RESTORE,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//将鼠标控制权转到该程序上<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetCapture(hCurWindow);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//鼠标定位到指定座标 <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetCursorPos(720,475);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//产生鼠标按键事件<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mouse_event(MOUSEEVENTF_LEFTDOWN+MOUSEEVENTF_LEFTUP,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;720,475,0,GetMessageExtraInfo());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//给其他应用程序以事件反应时间<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sleep(5000);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //获取下一窗口<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hCurWindow:=GetWindow(hCurWindow, GW_HWNDNEXT);<br>&nbsp; &nbsp; &nbsp;end;<br>end;<br>
 
忘了你要不影响当前程序运行,可在处理完成后用下列方法,激活自已的窗体即可!<br>SendMessage(GetDot.Handle,WM_SYSCOMMAND,SC_MINIMIZE,0);<br>SendMessage(GetDot.Handle,WM_SYSCOMMAND,SC_RESTORE,0);<br><br>其中GetDot为自己应用程序的窗口名
 
人心不足,有源程序当然最好啦!<br>我的邮箱:peacekeeper@cmmail.com
 
lycwg,你好。也给我一份源程序吧。<br>我的邮箱:qzhu@gliet.edu.cn
 
lycwg:<br>我想做一个类似PcAnyWhere的远程控制的程序(正常用途,非不良企图)<br>很希望看看你的程序,可以给我一份吗?<br>我的邮箱:tphou@etang.com
 
  我看过大虾的源程序,是定时把它从后台调到前台,再点鼠标。<br>可不可以不把它调到前台,而用发消息的办法呢???因为调到前台<br>会对我当前的工作有一定的影响。<br>
 
lycwg,你好。也给我一份源程序吧。玩一些要频繁按鼠标的游戏用。:)<br>我的邮箱:lich007@163.net<br>
 
如果那个位置正被另一个窗口遮住呢?
 
lycwg,你好。也给我一份源程序吧。<br>我的邮箱:jiangqw@263.net
 
&nbsp; 附加功能 &nbsp; 将问题提前 &nbsp; &nbsp;
 
我也要,我也要!!!!!!!<br><br>我的邮箱:daniel_zan@163.net<br><br>
 
me too!<br>我的地址: cumtzhangliwei@263.net
 
请问谁能发mouse_event的使用方法给我呀?sz_y@163.net
 
我想只要能够得到后台窗口的句并,就一切搞顶!我不知道你到底要发给哪个窗口!是用FindWINDOW<br>还是其他方法!反正获取有很多方法!一旦得到窗口句并,给应用程序/窗口发鼠标消息不就可以<br>了吗?<br>另外,可以利用钩子程序的回放来模拟鼠标,不过要甬道两个钩子!一个记录,一个回放!可以<br>很好实现你的想法!
 
iamphp:如果你还要继续讨论请定期提前你的帖子,如果不想继续讨论请结束帖子。<br>
 
高手在吗?
 
多人接受答案了。
 
后退
顶部