泣鬼神的问题……(10分)

  • 主题发起人 weisunding
  • 开始时间
W

weisunding

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在写一个外挂的输入法,用hook拦截键盘输入,出现如下问题(注释行)<br>请高手指点!<br>……<br>function KeyboardHookHandler(iCode: Integer; wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall; export;<br>const<br>&nbsp; _KeyPressMask = $80000000;<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>&nbsp; if (lParam and _KeyPressMask)=0 then begin<br>&nbsp; &nbsp; &nbsp;if (GetKeyState(VK_Control)&lt;0) and (wParam=Ord('B')) then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; WinExec('Notepad.exe',sw_Normal);<br>&nbsp; &nbsp; &nbsp;end<br>&nbsp; &nbsp; &nbsp;else begin<br>&nbsp; &nbsp; &nbsp; &nbsp; showmessage('You Press Key - ' + Char(wParam));<br>&nbsp; &nbsp; &nbsp; &nbsp; imeform.txtword.Caption:= Char(wParam); //加上这行后,就无法拦截键盘了<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //难道不能设置窗口控件的值吗?<br>&nbsp; &nbsp; &nbsp; end;<br>end;<br>end;
 
你的Hook DLL在其他的进程中运行,不能访问到你的控件,解决的办法是通过发消息<br>WM_COPYDATA通知你的主程序<br>
 
请给一个列子好吗?<br>WM_COPYDATA 怎么用?
 
泣鬼神?这不算什么,如果能使用泣就厉害了。[:(]
 
public<br>&nbsp; &nbsp; &nbsp;procedure Mymessage(var t:TWmCopyData);message WM_COPYDATA;<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form2: TForm2;<br><br>implementation<br><br>{$R *.DFM}<br><br>{ TForm2 }<br><br>procedure TForm2.Mymessage(var t: TWmCopyData);<br>begin<br>&nbsp; &nbsp;Edit1.text:=StrPas(t.CopyDataStruct^.lpData);//接受数据并显示。<br>end;<br><br>procedure TForm1.SpeedButton1Click(Sender: TObject);<br>var<br>&nbsp; &nbsp;ds: TCopyDataStruct;<br>&nbsp; &nbsp;hd: THandle;<br>begin<br>&nbsp; &nbsp;ds.cbData := Length(Edit1.Text) + 1;<br>&nbsp; &nbsp;GetMem(ds.lpData, ds.cbData); //为传递的数据区分配内存<br>&nbsp; &nbsp;StrCopy(ds.lpData, PChar(Edit1.Text));<br>&nbsp; &nbsp;Hd := FindWindow(nil, 'Form2'); // 获得接受窗口的句柄<br>&nbsp; &nbsp;if Hd &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; SendMessage(Hd, WM_COPYDATA, Handle,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Cardinal(@ds)) // 发送WM_COPYDATA消息<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; ShowMessage('目标窗口没找到!');<br>&nbsp; &nbsp;FreeMem(ds.lpData); //释放资源<br>end;<br><br>我找到了
 

Similar threads

I
回复
0
查看
526
import
I
I
回复
0
查看
636
import
I
I
回复
0
查看
663
import
I
顶部