unit udll;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;<br>var<br> myhook:Thandle;<br>procedure starthook;stdcall;export;<br>procedure unhook;stdcall;export;<br>function myHookProc(iCode: Integer; wParam: WPARAM; lParam: LPARAM):LRESULT;stdcall;<br>procedure log(ss:string);<br><br><br>implementation<br>procedure starthook;stdcall;<br>begin<br>myhook:=SetWindowsHookEx(WH_MOUSE,myHookProc,hInstance,0);<br>end;<br><br>function myHookProc(iCode: Integer; wParam: WPARAM; lParam: LPARAM):LRESULT;stdcall;<br>var<br> X, Y : Integer;<br>begin<br>result:=0;<br>if iCode<0 then <br> begin<br> result := CallNextHookEx(myHook, iCode, wParam, lParam);<br> exit;<br> end;<br>if (wParam = WM_LBUTTONDOWN) or (wParam=WM_NCLBUTTONDOWN) then<br>begin<br> X := PMouseHookStruct(lParam).pt.X;<br> Y := PMouseHookStruct(lParam).pt.Y;<br> log(#13+#10+'leftbutton click at' +'['+ inttostr(X) + ';' + inttostr(Y)+']');<br>end;<br>if (wParam = WM_NCMouseMove) or (wParam=WM_MOUSEMOVE) then<br>begin<br> X := PMouseHookStruct(lParam).pt.X;<br> Y := PMouseHookStruct(lParam).pt.Y;<br> log(' ['+inttostr(X) + ';' + inttostr(Y)+']');<br>end<br><br><br>result := CallNextHookEx(myHook, iCode, wParam, lParam);<br>end;<br>procedure unhook;stdcall;export;<br>begin<br> unhookwindowshookex(myhook);<br>end;<br>procedure log(ss:string);<br>var<br> file1:Tmemorystream;<br>begin<br> try<br> file1:=tmemorystream.Create;<br> try<br> file1.LoadFromFile('e:/delphi/log.txt');<br> except<br> end;<br> file1.Position:=file1.size;<br> file1.Write(ss[1],length(ss));<br> file1.SaveToFile('e:/delphi/log.txt');<br> finally<br> file1.free;<br> end;<br>end;<br>end.<br><br><br>library prjdll;<br><br>uses<br> udll in 'udll.pas';<br><br>{$R *.RES}<br><br>exports<br> starthook,unhook;<br>begin<br>end.<br>