用hook往另外程序的tedit写文本的问题,100(100分)

  • 主题发起人 主题发起人 z_cactic
  • 开始时间 开始时间
Z

z_cactic

Unregistered / Unconfirmed
GUEST, unregistred user!
我的hook写在dll里,当SetWindowsHookEx后,在另外一个程序里不管怎么动,都不会触发<br>MyWindowHook(code: Integer; wp: WPARAM; lp: LPARAM)这个函数,设断点也跟不进去,这是什么原因,<br>如果把SetWindowsHookEx里参数GetWindowThreadProcessId(Han ,nil)改为0断点是可以跟踪进去<br>但是if (pmsg.hwnd = handle) and (pmsg.message = WM_LBUTTONDOWN) then都是FALSE的。<br>我的程序如下。<br>procedure hookon(handle:thandle;chihan: thandle);stdcall;<br>procedure unhook;stdcall;<br>function MyWindowHook(code: Integer; wp: WPARAM; lp: LPARAM): LRESULT stdcall;<br>implementation<br>var<br>&nbsp; hk:HHOOK;<br>&nbsp; chihandle: thandle;<br>&nbsp; IsExit: boolean=false;<br>&nbsp; s: string;<br>procedure hookon(handle:thandle;chihan: thandle);<br>var<br>&nbsp; han: thandle;<br>begin<br>&nbsp; han := &nbsp;FindWindow('tform1', 'xxx');<br>&nbsp; if han = 0 then<br>&nbsp; &nbsp; exit;<br>&nbsp; hk := SetWindowsHookEx(WH_CALLWNDPROC,MyWindowHook,HInstance,<br>&nbsp; &nbsp; &nbsp;GetWindowThreadProcessId(Han ,nil));<br><br>end;<br>procedure unhook;<br>begin<br>&nbsp; UnhookWindowsHookEx(hk);<br>end;<br>function MyWindowHook(code: Integer; wp: WPARAM; lp: LPARAM): LRESULT stdcall;<br>var<br>&nbsp; &nbsp;pmsg:^CWPSTRUCT;<br>&nbsp; &nbsp;I:Integer;<br>&nbsp; &nbsp;lv: TLVITEM;<br>&nbsp; &nbsp;han: thandle;<br>&nbsp; &nbsp;handle,hedit: thandle;<br>&nbsp; &nbsp;ss: PChar;<br>begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; if Code &lt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := CallNextHookEx(hk, Code, wP, lP);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; pmsg:= Pointer(lp);<br>&nbsp; &nbsp; &nbsp; &nbsp; if code = HC_ACTION then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handle := &nbsp;FindWindow('tform1', 'xxx');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if handle = 0 then exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hedit := FindWindowEx(handle,0,'TEdit',nil);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if han = 0 then exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (pmsg.hwnd = handle) and (pmsg.message = WM_LBUTTONDOWN) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getmem(ss,30);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SendMessage(hedit,WM_SETTEXT,0,LPARAM(LPCTSTR('df')));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; freemem(ss);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; Result:= 1;<br>end;
 

Similar threads

I
回复
0
查看
762
import
I
I
回复
0
查看
676
import
I
后退
顶部