如何获取外部程序的某个button控件获得了焦点的消息.(200分)

  • 主题发起人 主题发起人 liudonghui
  • 开始时间 开始时间
L

liudonghui

Unregistered / Unconfirmed
GUEST, unregistred user!
如何获取外部程序的某个button控件获得了焦点的消息.<br>&nbsp; 问题一、应该用setwindowshookex(WH_CALLWNDPROC ,@hookproc,hinstance,0),还是<br>&nbsp; setwindowshookex(WH_GETMESSAGE ,@hookproc,hinstance,0)<br>&nbsp; 问题二、在上面的函数hookproc应使用什么参数,是<br>&nbsp; &nbsp; &nbsp;msg:=peventmsg(lparam)^;<br>&nbsp; &nbsp; &nbsp;if msg.message=wm_setfocus then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; 吗?
 
当外部程序的Button控件获得焦点消息时,向内部程序的某个窗口发送消息。<br>具体实现代码如下:<br>内部程序:<br>1.创建类名特定窗口。<br>type<br>&nbsp; TMyForm = Class(Tform)<br>&nbsp; public<br>&nbsp; &nbsp; procedure CreateParams(var Params: TCreateParams); override;<br>&nbsp; end;<br>const<br>&nbsp; MyFormName='My Delphi Form';<br>implementation<br>procedure CreateParams(var Params: TCreateParams); <br>begin<br>&nbsp; inherited;<br>&nbsp; Params.WinClassName:=MyFormName;<br>end;<br>外部程序:<br>1。首先调用API函数获得窗口句柄。假设为Handle。<br>2。发送消息通知内部程序。<br>&nbsp; type<br>&nbsp; TMyButton = Class(TButton)<br>&nbsp; Public<br>&nbsp; &nbsp; procedure WMSetFocus(var Message: TWMSetFocus);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;message WM_SETFOCUS;<br>&nbsp; end;<br>implementation<br>&nbsp; procedure TMyButton.WMSetFocus(var Message: TWMSetFocus);<br>&nbsp; begin<br>&nbsp; &nbsp; PostMessage(Handle,Message,Message.Wparam,Message.lparam);<br>&nbsp; &nbsp; {其他处理代码}<br>&nbsp; end;
 
我这里的外部程序指的是别人开发的程序。
 
接受答案了.
 
后退
顶部