方法一: 添加一Timer ,定义一个Tpoint变量pt,在onTimer中 getCursorPos(pt);label1.caption:=inttostr(pt.x)+' '+inttostr(pt.y);即可。<br><br><br>方法二:点右键显示坐标,主程序代码:<br> unit mainWnd;<br><br>interface<br><br>uses<br> { Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, ExtCtrls; }<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs,shellapi, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Label1: TLabel;<br> Button1: TButton;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> public<br> { Public declarations }<br><br> procedure wndProc(var mess:TMessage);override;<br> private<br> { Private declara }<br><br> end;<br><br>var <br> Form1: TForm1;<br> myMessage:UINT;<br>implementation<br><br>{$R *.dfm}<br>procedure installMouseHook;external './hookdll.dll';<br> procedure unHookMouseHook;external './hookdll.dll';<br> procedure byMain( wnd:Hwnd);external './hookdll.dll';<br>procedure TForm1.wndProc(var mess:TMessage);<br>begin<br> if mess.Msg=myMessage then<br> begin<br> label1.Caption:='X'+inttostr(mess.wparam)+' Y'+inttostr(mess.lparam);<br> end else<br> inherited;<br>end;<br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> byMain(form1.handle);<br> installMouseHook;<br><br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> unHookMouseHook;<br>end;<br>begin<br> myMessage:=registerWindowMessage(pchar('sxw'));<br>end.<br> //dll中代码为<br><br>library hookdll;<br><br> uses<br> ShareMem,<br> Windows,<br> Classes,<br> Controls,<br> Dialogs,<br> SysUtils,<br> shellapi,<br> Qt;<br><br>{$R *.res}<br><br><br><br> var mousehook:HHook;<br> callMessage:UINT;<br> mainwindow:Hwnd;<br>procedure byMain(wnd:Hwnd);<br>begin<br> mainWindow:=wnd;<br> end;<br>function MouseProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>var p:^MOUSEHOOKSTRUCT;<br>begin<br><br> p:=ptr(lParam);<br> if (wParam=516) and (ncode>=0) then<br> sendMessage(hwnd_broadCast,callMessage,p^.pt.x,p^.pt.y);<br> result:=callNextHookEx(mouseHook,nCode,wParam,lParam);<br> end;<br><br><br><br> procedure installMouseHook;stdcall;<br> begin<br> mousehook:=setWindowsHookEx(WH_MOUSE,@MouseProc,Hinstance,0);<br> end;<br>procedure unHookMouseHook;stdcall;<br>begin<br> if mousehook<>0 then<br> begin<br> unHookWindowsHookEx(mousehook);<br> end;<br>end;<br><br>exports<br> unHookMouseHook,<br> installMouseHook,<br> byMain;<br><br>begin<br> callMessage:=registerWindowMessage('sxw');<br><br>end.<br><br>结帐吧!