Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4765063
  • 博文数量: 206
  • 博客积分: 5240
  • 博客等级: 大校
  • 技术积分: 3224
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-12 21:40
文章分类

全部博文(206)

文章存档

2013年(13)

2012年(8)

2011年(33)

2010年(152)

我的朋友

分类: WINDOWS

2010-10-07 23:27:50

钩子类型介绍(续二)

钩子类型1314WH_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一样的常量,可以使用该值来决定钩子子程是被哪里调用的。

钩子类型15WH_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方法。

阅读(1012) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~