全部源码给你:<br>library MHK;<br>{<br> 使用内存映象文件的鼠标勾子动态库<br> 主要用途是取得窗口文本(支持Win2k And WinXP)<br>}<br><br>uses<br> windows,<br> MapFileUnit in 'MapFileUnit.pas',<br> HKPROC in 'HKPROC.PAS';<br><br>exports<br> EnableMouseHook,<br> DisableMouseHook;<br><br>begin<br> YYHMouseMsg := RegisterWindowMessage(PChar(MouseHookMsg));<br> HMapFile := 0;<br> MapCommonData(CommonData,HMapFile);<br> hNextHookProc := 0;<br> procSaveExit := ExitProc;<br> ExitProc := @MouseHookExit;<br>end.<br><br>unit HKProc;<br><br>interface<br><br>uses<br> Windows, Messages, MapFileUnit;<br><br>var<br> hNextHookProc: HHook;<br> procSaveExit: Pointer;<br> YYHMouseMsg : UINT;<br> HMapFile:THandle;<br> CommonData
CommonData;<br><br>function MouseHookHandler(iCode: Integer;<br> wParam: WPARAM;<br> lParam: LPARAM): LRESULT; stdcall; export;<br>function EnableMouseHook(hld:hwnd): BOOL; stdcall; export;<br>function DisableMouseHook: BOOL; stdcall; export;<br>procedure MouseHookExit; far;<br><br>implementation<br><br>{function BroadcastSystemMessage(Flags: DWORD; Recipients: PDWORD;<br> uiMessage: UINT; wParam: WPARAM; lParam: LPARAM): Longint; <br> stdcall; external 'user32.dll'; }<br><br>function MouseHookHandler(iCode: Integer;<br> wParam: WPARAM;<br> lParam: LPARAM): LRESULT; stdcall; export;<br>begin<br> Result := 0;<br> If iCode < 0 Then<br> begin<br> Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);<br> Exit;<br> end;<br><br> CommonData.MouseMsg :=wParam;<br> CommonData.MousePos :=PMouseHookStruct(lparam).pt;<br> CommonData.targetHwnd :=PMouseHookStruct(lparam).hwnd;<br> GetWindowText(CommonData.targetHwnd,CommonData.wndtext,MAX_PATH+1);<br> CommonData.HitCode := PMouseHookStruct(lparam).wHitTestCode;<br> CommonData.ExInfo :=PMouseHookStruct(lparam).dwExtraInfo;<br><br> PostMessage(CommonData.CallBackHandle, YYHMouseMsg, wParam, lParam);<br>end;<br><br>function EnableMouseHook(hld:hwnd): BOOL; stdcall; export;<br>var<br> mk:0.._MOUSE_EVENT ;<br>begin<br> CommonData.CallBackHandle := hld;<br> Result := False;<br> if hNextHookProc <> 0 then Exit;<br><br> hNextHookProc := SetWindowsHookEx(WH_MOUSE,<br> MouseHookHandler,<br> HInstance,<br> 0);<br> Result := hNextHookProc <> 0;<br>end;<br><br><br>function DisableMouseHook: BOOL; stdcall; export;<br>begin<br> if hNextHookProc <> 0 then<br> begin<br> UnhookWindowshookEx(hNextHookProc);<br> hNextHookProc := 0;<br> MessageBeep(0);<br> MessageBeep(0);<br> end;<br> Result := hNextHookProc = 0;<br>end;<br><br><br>procedure MouseHookExit;<br>begin<br> if hNextHookProc <> 0 then DisableMouseHook;<br> ExitProc := procSaveExit;<br> if CommonData<>nil then UnMapCommonData(CommonData,HMapFile);<br>end;<br><br>end.<br><br>unit MapFileUnit;<br><br>interface<br><br>uses<br> windows;<br><br>const<br> MapFileName='YYH_MOUSEHOOKMAP';<br> MouseHookMsg='WM_YYH_MOUSE';<br><br>type<br> pCommonData = ^TCommonData;<br> TCommonData = record<br> CallBackHandle: HWnd;<br> MouseMsg :Cardinal;<br> MousePos :TPoint;<br> HitCode :Cardinal;<br> ExInfo :Cardinal;<br> targetHwnd: HWND;<br> wndtext: array[0..MAX_PATH]of char;<br> end;<br><br>procedure MapCommonData(var CommonData
CommonData;var HMapFile:THandle);<br>procedure UnMapCommonData(var CommonData
CommonData;var HMapFile:THandle);<br><br>implementation<br><br>procedure MapCommonData(var CommonData
CommonData;var HMapFile:THandle);<br>var FirstCall: Boolean;<br>begin<br> HMapFile:=OpenFileMapping(FILE_MAP_WRITE, False, PChar(MapFileName));<br> FirstCall:=(HMapFile = 0);<br> if FirstCall then<br> HMapFile:=CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,<br> 0,SizeOf(TCommonData),<br> PChar(MapFileName));<br> CommonData:= MapViewOfFile(HMapFile, FILE_MAP_WRITE, 0, 0, 0);<br> if FirstCall then FillChar(CommonData^, SizeOf(TCommonData), 0);<br>end;<br><br>procedure UnMapCommonData(var CommonData
CommonData;var HMapFile:THandle);<br>begin<br> try<br> UnMapViewOfFile(CommonData);<br> CommonData := nil;<br> CloseHandle(HMapFile);<br> HMapFile := 0;<br> except<br> MessageBox(0,<br> 'Error when free MapFile!',<br> 'YYH MouseHook',<br> MB_OK);<br> end; //try<br>end;<br><br>end.<br>记得给我分啊!!![
][
][
]