如何使用hook,或者其他方法得到对方程序中文本框的内容。--100fen (100分)

  • 主题发起人 主题发起人 xch28
  • 开始时间 开始时间
X

xch28

Unregistered / Unconfirmed
GUEST, unregistred user!
如题。<br>请不要给出sendmessage这样的方法,我试过了,不行。<br>可以参考下面的帖子,是一个问题。<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=1882792<br>如果回答了,分可以全给。谢谢。
 
全部源码给你:<br>library MHK;<br>{<br>&nbsp;使用内存映象文件的鼠标勾子动态库<br>&nbsp; &nbsp;主要用途是取得窗口文本(支持Win2k And WinXP)<br>}<br><br>uses<br>&nbsp; windows,<br>&nbsp; MapFileUnit in 'MapFileUnit.pas',<br>&nbsp; HKPROC in 'HKPROC.PAS';<br><br>exports<br>&nbsp; EnableMouseHook,<br>&nbsp; DisableMouseHook;<br><br>begin<br>&nbsp; YYHMouseMsg := RegisterWindowMessage(PChar(MouseHookMsg));<br>&nbsp; HMapFile := 0;<br>&nbsp; MapCommonData(CommonData,HMapFile);<br>&nbsp; hNextHookProc := 0;<br>&nbsp; procSaveExit := ExitProc;<br>&nbsp; ExitProc := @MouseHookExit;<br>end.<br><br>unit HKProc;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, MapFileUnit;<br><br>var<br>&nbsp; hNextHookProc: HHook;<br>&nbsp; procSaveExit: Pointer;<br>&nbsp; YYHMouseMsg : UINT;<br>&nbsp; HMapFile:THandle;<br>&nbsp; CommonData:pCommonData;<br><br>function MouseHookHandler(iCode: Integer;<br>&nbsp; wParam: WPARAM;<br>&nbsp; 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>&nbsp; uiMessage: UINT; wParam: WPARAM; lParam: LPARAM): Longint; <br>&nbsp; stdcall; external 'user32.dll'; &nbsp;}<br><br>function MouseHookHandler(iCode: Integer;<br>&nbsp; wParam: WPARAM;<br>&nbsp; lParam: LPARAM): LRESULT; stdcall; export;<br>begin<br>&nbsp; Result := 0;<br>&nbsp; If iCode &lt; 0 Then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br><br>&nbsp; CommonData.MouseMsg :=wParam;<br>&nbsp; CommonData.MousePos :=PMouseHookStruct(lparam).pt;<br>&nbsp; CommonData.targetHwnd :=PMouseHookStruct(lparam).hwnd;<br>&nbsp; GetWindowText(CommonData.targetHwnd,CommonData.wndtext,MAX_PATH+1);<br>&nbsp; CommonData.HitCode := PMouseHookStruct(lparam).wHitTestCode;<br>&nbsp; CommonData.ExInfo :=PMouseHookStruct(lparam).dwExtraInfo;<br><br>&nbsp; PostMessage(CommonData.CallBackHandle, YYHMouseMsg, wParam, lParam);<br>end;<br><br>function EnableMouseHook(hld:hwnd): BOOL; stdcall; export;<br>var<br>&nbsp; &nbsp;mk:0.._MOUSE_EVENT ;<br>begin<br>&nbsp; CommonData.CallBackHandle := hld;<br>&nbsp; Result := False;<br>&nbsp; if hNextHookProc &lt;&gt; 0 then Exit;<br><br>&nbsp; hNextHookProc := SetWindowsHookEx(WH_MOUSE,<br>&nbsp; &nbsp; MouseHookHandler,<br>&nbsp; &nbsp; HInstance,<br>&nbsp; &nbsp; 0);<br>&nbsp; Result := hNextHookProc &lt;&gt; 0;<br>end;<br><br><br>function DisableMouseHook: BOOL; stdcall; export;<br>begin<br>&nbsp; if hNextHookProc &lt;&gt; 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; UnhookWindowshookEx(hNextHookProc);<br>&nbsp; &nbsp; hNextHookProc := 0;<br>&nbsp; &nbsp; MessageBeep(0);<br>&nbsp; &nbsp; MessageBeep(0);<br>&nbsp; end;<br>&nbsp; Result := hNextHookProc = 0;<br>end;<br><br><br>procedure MouseHookExit;<br>begin<br>&nbsp; if hNextHookProc &lt;&gt; 0 then DisableMouseHook;<br>&nbsp; ExitProc := procSaveExit;<br>&nbsp; if CommonData&lt;&gt;nil then UnMapCommonData(CommonData,HMapFile);<br>end;<br><br>end.<br><br>unit MapFileUnit;<br><br>interface<br><br>uses<br>&nbsp; windows;<br><br>const<br>&nbsp; MapFileName='YYH_MOUSEHOOKMAP';<br>&nbsp; MouseHookMsg='WM_YYH_MOUSE';<br><br>type<br>&nbsp; pCommonData = ^TCommonData;<br>&nbsp; TCommonData = record<br>&nbsp; &nbsp; CallBackHandle: HWnd;<br>&nbsp; &nbsp; MouseMsg :Cardinal;<br>&nbsp; &nbsp; MousePos :TPoint;<br>&nbsp; &nbsp; HitCode :Cardinal;<br>&nbsp; &nbsp; ExInfo :Cardinal;<br>&nbsp; &nbsp; targetHwnd: HWND;<br>&nbsp; &nbsp; wndtext: array[0..MAX_PATH]of char;<br>&nbsp; end;<br><br>procedure MapCommonData(var CommonData:pCommonData;var HMapFile:THandle);<br>procedure UnMapCommonData(var CommonData:pCommonData;var HMapFile:THandle);<br><br>implementation<br><br>procedure MapCommonData(var CommonData:pCommonData;var HMapFile:THandle);<br>var FirstCall: Boolean;<br>begin<br>&nbsp; HMapFile:=OpenFileMapping(FILE_MAP_WRITE, False, PChar(MapFileName));<br>&nbsp; FirstCall:=(HMapFile = 0);<br>&nbsp; if FirstCall then<br>&nbsp; &nbsp; HMapFile:=CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,SizeOf(TCommonData),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PChar(MapFileName));<br>&nbsp; CommonData:= MapViewOfFile(HMapFile, FILE_MAP_WRITE, 0, 0, 0);<br>&nbsp; if FirstCall then FillChar(CommonData^, SizeOf(TCommonData), 0);<br>end;<br><br>procedure UnMapCommonData(var CommonData:pCommonData;var HMapFile:THandle);<br>begin<br>&nbsp; try<br>&nbsp; &nbsp; UnMapViewOfFile(CommonData);<br>&nbsp; &nbsp; CommonData := nil;<br>&nbsp; &nbsp; CloseHandle(HMapFile);<br>&nbsp; &nbsp; HMapFile := 0;<br>&nbsp; except<br>&nbsp; &nbsp; MessageBox(0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Error when free MapFile!',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'YYH MouseHook',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MB_OK);<br>&nbsp; end; //try<br>end;<br><br>end.<br>记得给我分啊!!![:D][:D][:D]
 
谢谢,我先试试
 
http://www.playicq.com/datanew/gpsyshook.zip
 
这里有源码:<br>http://www.encryptpe.com/bckj.zip<br>HOOK目录。<br><br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=1862254
 
多人接受答案了。
 
后退
顶部