钩子类型介绍(续二)
钩子类型13、14:WH_MSGFILTER and WH_SYSMSGFILTER Hooks
The WH_MSGFILTER and WH_SYSMSGFILTER hooks enable you to monitor messages about to be processed by a menu, scroll bar, message box, or dialog box, and to detect when a different window is about to be activated as a result of the user's pressing the ALT+TAB or ALT+ESC key combination. The WH_MSGFILTER hook can only monitor messages passed to a menu, scroll bar, message box, or dialog box created by the application that installed the hook procedure. The WH_SYSMSGFILTER hook monitors such messages for all applications.
WH_MSGFILTER 和 WH_SYSMSGFILTER钩子允许监视即将由菜单、滚动条、消息框、对话框处理的消息,并且在用户按下了ALT+TAB 或者ALT+ESC组合键后,检测何时一个不同的窗口将被激活。WH_MSGFILTER钩子仅仅能监视传递到菜单、滚动条、消息框或者由安装了钩子子程的应用程序建立的对话框的消息。WH_SYSMSGFILTER钩子监视所有应用程序的这类消息。
The WH_MSGFILTER and WH_SYSMSGFILTER hooks enable you to perform message filtering during modal loops that is equivalent to the filtering done in the main message loop. For example, an application often examines a new message in the main loop between the time it retrieves the message from the queue and the time it dispatches the message, performing special processing as appropriate. However, during a modal loop, the system retrieves and dispatches messages without allowing an application the chance to filter the messages in its main message loop. If an application installs a WH_MSGFILTER or WH_SYSMSGFILTER hook procedure, the system calls the procedure during the modal loop.
WH_MSGFILTER 和WH_SYSMSGFILTER钩子允许在模式循环期间执行消息过滤,这和在主消息循环中执行过滤是等效的。例如,应用程序在它从队列中收到消息到分派消息期间,经常在主循环中检查新的消息,执行适当的处理。然而,在模式循环期间,系统会收到、分派消息,但是并不给应用程序机会去过滤主消息循环中的消息。如果应用程序安装了WH_MSGFILTER 或者 WH_SYSMSGFILTER钩子子程,系统会在模式循环期间调用钩子子程。
An application can call the WH_MSGFILTER hook directly by calling the CallMsgFilter function. By using this function, the application can use the same code to filter messages during modal loops as it uses in the main message loop. To do so, encapsulate the filtering operations in a WH_MSGFILTER hook procedure and call CallMsgFilter between the calls to the GetMessage and DispatchMessage functions.
应用程序可以通过调用CallMsgFilter方法直接调用WH_MSGFILTER钩子。通过使用该方法,应用程序可以像在主消息循环中一样,使用同样的代码来过滤消息。这样做呢,可以在WH_MSGFILTER钩子子程中封装过滤的操作,在调用GetMessage和 DispatchMessage方法期间调用CallMsgFilter。
while (GetMessage(&msg, (HWND) NULL, 0, 0))
{
if (!CallMsgFilter(&qmsg, 0))
DispatchMessage(&qmsg);
}
The last argument of CallMsgFilter is simply passed to the hook procedure; you can enter any value. The hook procedure, by defining a constant such as MSGF_MAINLOOP, can use this value to determine where the procedure was called from.
CallMsgFilter的最后一个参数简单的传递给钩子子程;可以输入任何值。钩子子程,通过定义像MSGF_MAINLOOP一样的常量,可以使用该值来决定钩子子程是被哪里调用的。
钩子类型15:WH_SHELL Hook
A shell application can use the WH_SHELL hook to receive important notifications. The system calls a WH_SHELL hook procedure when the shell application is about to be activated and when a top-level window is created or destroyed.
加壳程序可以使用WH_SHELL钩子来接收重要的通知。当加壳程序即将被激活时、当处在最顶层的窗口被创建或者销毁时,系统会调用WH_SHELL钩子子程。
Note that custom shell applications do not receive WH_SHELL messages. Therefore, any application that registers itself as the default shell must call the SystemParametersInfo function with SPI_SETMINIMIZEDMETRICS before it (or any other application) can receive WH_SHELL messages.
注意:常规加壳程序并不接收WH_SHELL消息。因此,任何将自己注册为默认外壳的应用程序必须在它(或者任何其它应用程序)能够接收WH_SHELL消息之前调用带有SPI_SETMINIMIZEDMETRICS 的SystemParametersInfo方法。
Helios 2007-4-8