希望得到帮助------->关于鼠标钩子的问题: ( 积分: 100 )

  • 主题发起人 主题发起人 wp231957
  • 开始时间 开始时间
W

wp231957

Unregistered / Unconfirmed
GUEST, unregistred user!
1. 主程序如何获得当前鼠标的坐标(本程序窗口以外的鼠标坐标)<br> &nbsp; <br><br>最好有原代码,谢谢
 
1. 主程序如何获得当前鼠标的坐标(本程序窗口以外的鼠标坐标)<br> &nbsp; <br><br>最好有原代码,谢谢
 
用WH_JOURNALRECORD钩子,临时写的,简单明了。<br>unit Unit1;<br>interface<br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;procedure FormDestroy(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;Form1: TForm1;<br> &nbsp;JHook: THandle;<br>implementation<br>{$R *.dfm}<br><br>function JournalProc(Code, wParam: Integer; var EventStrut: TEventMsg): Integer; stdcall;<br>var<br> &nbsp;Char1: PChar;<br> &nbsp;s: string;<br>begin<br> &nbsp;Result := CallNextHookEx(JHook, Code, wParam, Longint(@EventStrut));<br> &nbsp;if Code = HC_ACTION then<br> &nbsp;begin<br> &nbsp; if (EventStrut.message = WM_MOUSEMOVE) then<br> &nbsp; &nbsp; Form1.Caption := format('X=%d Y=%d',[EventStrut.paramL, EventStrut.paramH]);<br> &nbsp;end;<br>end; <br><br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> //安装钩子<br> JHook := SetWindowsHookEx(WH_JOURNALRECORD, @JournalProc, hInstance, 0);<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br> &nbsp;UnhookWindowsHookEx(JHook); //卸载钩子<br> &nbsp;JHook := 0;<br>end;<br>end.
 
先谢谢,我研究一下,如果测试成功,分数是一定给的
 
TO YUZI:<br><br>您写的是免DLL的,,,,能不能提供一个DLL(还有主程序如何调用)的呢
 
老大,这段程序确实够准确,,可是它会把我的进程搞死了啊<br><br>不知道哪里有BUG
 
发消息给主程序即可
 
后退
顶部