怎么不好用?下面的DLL是我以前写的测试,可以钩到那两个消息,你参考一下吧。<br><br>MsgHook.dpr<br>--------------------------------------------------------<br>library MsgHook;<br><br>uses windows, Messages;<br><br>var<br> hNextHookProc: HHook;<br> procSaveExit: Pointer;<br> iReceiver, iFormCreateMsg, iFormDestroyMsg:integer;<br> pAppHandle: pInteger;<br> HMapFile:THandle;<br><br>function MousePosHookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; <br>begin<br> if iCode < 0 then<br> Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam) <br> else<br> begin<br> if iCode = HSHELL_WINDOWCREATED then //窗体Create消息<br> SendMessage(pAppHandle^, iFormCreateMsg, wParam, 0)<br> else if iCode = HSHELL_WINDOWDESTROYED then //窗体destroy消息<br> SendMessage(pAppHandle^, iFormDestroyMsg, wParam, 0);<br> Result := 0;<br> end;<br>end;<br><br>function EnableMouseHook(hld:hwnd): BOOL; export; //激活钩子<br>begin<br> Result := False;<br> pAppHandle^ := 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; //共享内存,用来与调用它的App交换数据<br>var FirstCall: Boolean;<br>begin<br> HMapFile:=OpenFileMapping(FILE_MAP_WRITE, False, 'CommonData');<br> FirstCall:=(HMapFile = 0);<br> if FirstCall then<br> HMapFile:=CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, SizeOf(pInteger), 'CommonData');<br> new(pAppHandle);<br> pAppHandle := MapViewOfFile(hMapFile, file_map_write, 0, 0, 0); <br> if FirstCall then FillChar(pAppHandle^, SizeOf(pInteger), 0);<br>end;<br><br>procedure IntoDll; stdcall;<br>begin<br> iFormCreateMsg := RegisterWindowMessage('FormCreateMsg');<br> iFormDestroyMsg := RegisterWindowMessage('FormDestroyMsg');<br> iReceiver:=0;<br>end;<br><br>exports<br> EnableMouseHook, DisableMouseHook;<br><br>begin<br> InToDll;<br> MapCommonData;<br> hNextHookProc := 0;<br> procSaveExit := ExitProc;<br> ExitProc := @MouseHookExit;<br>end.