用WH_JOURNALRECORD钩子,临时写的,简单明了。<br>unit Unit1;<br>interface<br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs;<br><br>type<br> TForm1 = class(TForm)<br> procedure FormCreate(Sender: TObject);<br> procedure FormDestroy(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br> JHook: THandle;<br>implementation<br>{$R *.dfm}<br><br>function JournalProc(Code, wParam: Integer; var EventStrut: TEventMsg): Integer; stdcall;<br>var<br> Char1: PChar;<br> s: string;<br>begin<br> Result := CallNextHookEx(JHook, Code, wParam, Longint(@EventStrut));<br> if Code = HC_ACTION then<br> begin<br> if (EventStrut.message = WM_MOUSEMOVE) then<br> Form1.Caption := format('X=%d Y=%d',[EventStrut.paramL, EventStrut.paramH]);<br> 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> UnhookWindowsHookEx(JHook); //卸载钩子<br> JHook := 0;<br>end;<br>end.