钩子教程 - 原理(十九) : MessageProc

原文地址:http://www.zdexe.com/program/201004/593.html

方法14 :MessageProc Function

The MessageProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function after an input event occurs in a dialog box, message box, menu, or scroll bar, but before the message generated by the input event is processed. The hook procedure can monitor messages for a dialog box, message box, menu, or scroll bar created by a particular application or all applications. 

  MessageProc钩子子程是同SetWindowsHookEx方法一起使用的、应用程序或者库定义的回调方法。在对话框,消息框,菜单,滚动条的输入事件发生后、在这些输入事件生成的消息被处理之前,系统调用该方法。钩子子程可以监视特定的程序或者所有程序生成的对话框,消息框,菜单或者滚动条的消息。

 

The HOOKPROC type defines a pointer to this callback function. MessageProc is a placeholder for the application-defined or library-defined function name. HOOKPROC类型定义了指向该回调函数的指针。MessageProc是程序定义的或者库定义的方法名字。

Syntax语法

LRESULT CALLBACK MessageProc(      

        int code,
    WPARAM wParam,
    LPARAM lParam
);

Parameters参数

code :[in] Specifies the type of input event that generated the message. If code is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and return the value returned by CallNextHookEx. This parameter can be one of the following values. 指定生成消息的输入事件的类型。如果code小于0,钩子子程必须将消息传递给CallNextHookEx方法,自己不进行任何进一步处理,并且要返回由方法CallNextHookEx返回的返回值。该参数可以时下列方法之一。

1.MSGF_DDEMGR :The input event occurred while the Dynamic Data Exchange Management Library (DDEML) was waiting for a synchronous transaction to finish. 当DDEML正在等待同步传输结束时,该输入事件发生。

2.MSGF_DIALOGBOX :The input event occurred in a message box or dialog box. 输入事件在消息框或者对话框中发生。

3.MSGF_MENU :The input event occurred in a menu. 输入事件在菜单中发生。

4.MSGF_SCROLLBAR :The input event occurred in a scroll bar.输入事件在滚动条中发生。

wParam :This parameter is not used. 该参数未被使用。

lParam :[in] Pointer to an MSG structure. 指向MSG结构的指针。

Return Value返回值

If code is less than zero, the hook procedure must return the value returned byCallNextHookEx.

If code is greater than or equal to zero, and the hook procedure did not process the message, it is highly recommended that you call CallNextHookEx and return the value it returns; otherwise, other applications that have installed WH_MSGFILTER hooks will not receive hook notifications and may behave incorrectly as a result. If the hook procedure processed the message, it may return a nonzero value to prevent the system from passing the message to the rest of the hook chain or the target window procedure.

如果code小于0,钩子子程必须返回由方法CallNextHookEx返回的返回值。如果code大于等于0,而且钩子子程还没有处理该消息,强烈要求调用CallNextHookEx方法并返回由它返回的返回值;否则,其它已经安装了WH_MSGFILTER钩子的应用程序将收不到钩子通知,可能导致行为的错误。如果钩子子程已经处理了该消息,应该返回非0值,以组织系统将消息传递给钩子链表中剩下的钩子或者目标窗口子程。

Remarks备注

An application installs the hook procedure by specifying the WH_MSGFILTER hook type and a pointer to the hook procedure in a call to the SetWindowsHookEx function.

If an application that uses the DDEML and performs synchronous transactions must process messages before they are dispatched, it must use the WH_MSGFILTER hook.

应用程序通过下面方法来安装钩子:指定WH_MSGFILTER钩子类型;指定在调用SetWindowsHookEx的方法中指向钩子子程的指针。

使用DDEML、执行同步传递的应用程序应该在消息被分发前进行处理,必须使用WH_MSGFILTER钩子。 

posted @ 2016-05-17 14:48  C/C++/Python/Java  阅读(590)  评论(0编辑  收藏  举报