呵呵,只给我75分?<br><br>//程序教乱,没时间整理。凑和作看看吧。<br><br>library capwnd;<br><br>uses<br> SysUtils,<br> Classes,<br> Dialogs,<br> windows,<br> messages;<br><br>type TCommonData = record<br> HookID:HHook;<br> CallBackHandle:HWnd;<br> end;<br>var<br> hNextHookProc: HHook;<br> procSaveExit: Pointer;<br> receiver,msg_id:integer;<br>var HMapFile:THandle;<br> CommonData:^TCommonData;<br><br>const STR_MSGMOUSEPOS
char='WM_MOUSEPOS';<br><br>function MousePosHookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;<br>var h
Char;<br>begin<br> if iCode < 0 then<br> begin<br> Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);<br> end<br> else<br> begin<br> if iCode = HSHELL_WINDOWDESTROYED then<br> begin<br>// ShowMessage('Ok, HSHELL_WINDOWDESTROYED');<br>// h:=windowfrompoint(PMouseHookStruct(lParam).pt);<br> Sendmessage(CommonData.CallBackHandle,msg_id,wParam,0);<br> end;<br> Result := 0;<br> end;<br>end;<br><br>function EnableMouseHook(hld:hwnd): BOOL; export;<br>begin<br> Result := False;<br> CommonData.CallBackHandle:=hld;<br> if hNextHookProc <> 0 then Exit;<br> hNextHookProc := SetWindowsHookEx(WH_SHELL, MousePosHookHandler,Hinstance, 0);<br> Result :=hNextHookProc <> 0 ;<br>end;<br><br>function DisableMouseHook: BOOL; export;<br>begin<br> if hNextHookProc <> 0 then<br> begin<br> UnhookWindowshookEx(hNextHookProc);<br> hNextHookProc := 0;<br> end;<br> Result := hNextHookProc = 0;<br>end;<br><br>procedure MouseHookExit;<br>begin<br> if hNextHookProc <> 0 then DisableMouseHook;<br> ExitProc := procSaveExit;<br>end;<br><br>procedure MapCommonData;<br>var FirstCall: Boolean;<br>begin<br> HMapFile:=OpenFileMapping(FILE_MAP_WRITE, False, 'sjhdfasdfasdfasd');<br> FirstCall:=(HMapFile = 0);<br> if FirstCall then<br> HMapFile:=CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,0,SizeOf(TCommonData),'sjhdfasdfasdfasd');<br> CommonData:= MapViewOfFile(HMapFile, FILE_MAP_WRITE, 0, 0, 0);<br> if FirstCall then FillChar(CommonData^, SizeOf(TCommonData), 0);<br>end;<br><br><br>procedure IntoDll; stdcall;<br>begin<br> msg_id:= RegisterWindowMessage(STR_MSGMOUSEPOS);<br> receiver:=0;<br>end;<br><br>exports<br> EnableMouseHook,<br> DisableMouseHook;<br>begin<br> Intodll;<br> MapCommonData;<br> hNextHookProc := 0;<br> procSaveExit := ExitProc;<br> ExitProc := @MouseHookExit;<br>end.<br><br><br><br><br>unit unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Edit1: TEdit;<br> procedure FormCreate(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> procedure WndProc(var Mess: TMessage); override;<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br> msg_id:integer;<br>const STR_MSGMOUSEPOS
char='WM_MOUSEPOS';<br><br>implementation<br><br>function EnableMouseHook(hld:hwnd): BOOL; external 'capwnd.DLL';<br>function DisableMouseHook: BOOL; external 'capwnd.DLL';<br><br>{$R *.DFM}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> msg_id:=RegisterWindowMessage(STR_MSGMOUSEPOS);<br> EnableMouseHook(handle);<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> DisableMouseHook;<br>end;<br>procedure TForm1.WndProc(var Mess: TMessage);<br>var<br> Str:array [0..255] of char;<br>begin<br> if (mess.msg=msg_id) then<br> begin<br> GetWindowText(mess.WParam,Str,256);<br> Edit1.Text:=str;<br> end;<br> inherited;<br>end;<br><br>end.