如何截获发往指定窗口的消息(50分)

  • 主题发起人 主题发起人 vess
  • 开始时间 开始时间
谢谢可以说详细一点吗?
 
如果想知道其他进程的指定窗口的消息我想应该用hook.wndproc是窗口类的窗口函数。
 
有否例子提供,加分!
 
贴一个,没验证过。
看着玩吧。

一程序,按其主窗体上的一个按钮后,会打开另一个窗体,如该窗体已打开,
则会被设成当前窗体.现我想截获主窗体的按钮被按下的消息,这样就可能打开我的
窗体,而非该程序原来的窗体.

HWND wnd = 按钮所在窗口的句柄;
WNDPROC oldProc = SetWindowLong(wnd, GWL_WNDPROC, yourProc);
...
用完后恢复 GWL_WNDPROC。

WNDPROC yourProc(...)
{
if (那个按钮被按下) then 想干什么就干什么
else CallWndProc(oldProc);
...
}
 
SetWindowsHookEx Function

--------------------------------------------------------------------------------

The SetWindowsHookEx function installs an application-defined hook procedure
into a hook chain. You would install a hook procedure to monitor the system
for certain types of events. These events are associated either with a specific
thread or with all threads in the same desktop as the calling thread.

Syntax

HHOOK SetWindowsHookEx( int idHook,
HOOKPROC lpfn,
HINSTANCE hMod,
DWORD dwThreadId
);
Parameters

idHook
[in] Specifies the type of hook procedure to be installed. This parameter can
be one of the following values.
-----------------------------------------------------------------------
WH_CALLWNDPROC
[red]Installs a hook procedure that monitors messages before the system sends them
to the destination window procedure. For more information, see the CallWndProc
hook procedure.[/red]
-----------------------------------------------------------------------
 

Similar threads

S
回复
0
查看
699
SUNSTONE的Delphi笔记
S
S
回复
0
查看
787
SUNSTONE的Delphi笔记
S
S
回复
0
查看
839
SUNSTONE的Delphi笔记
S
S
回复
0
查看
820
SUNSTONE的Delphi笔记
S
后退
顶部