钩子(HOOK)函数教程(九)

时间:2010年04月21日 点击:784

方法3 CallWndProc Function

The CallWndProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function.

CallWndProc钩子子程是与SetWindowsHookEx一起使用的、用户定义的或者库定义的回调函数。

The HOOKPROC type defines a pointer to this callback function. CallWndProc is a placeholder for the application-defined or library-defined function name.

HOOKPROC类型定义了指向该回调函数的指针。CallWndProc是程序定义的或者库定义的方法名字。

Syntax :语法    LRESULT CALLBACK CallWndProc(      
                   Int nCode,

          WPARAM wParam,

          LPARAM lParam

);

Parameters 参数:

nCode   [in] Specifies whether the hook procedure must process the message. If nCode is HC_ACTION, the hook procedure must process the message. If nCode is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and must return the value returned by CallNextHookEx.

指定钩子子程是否必须处理该消息。如果nCodeHC_ACTION,钩子子程就必须处理该消息。如果nCode小于0,钩子子程就必须将该消息传递给CallNextHookEx,自己不对消息进行进一步的处理,必须返回由CallNextHookEx 方法返回的返回值。

wParam [in] Specifies whether the message was sent by the current thread. If the message was sent by the current thread, it is nonzero; otherwise, it is zero. 指定消息是否由当前线程发出。如果消息是由当前线程发出的,该值就是非0;否则,就是0

lParam [in] Pointer to a CWPSTRUCT structure that contains details about the message.

指向CWPSTRUCT结构的指针,该结构含有消息的细节信息。

Return Value 返回值

If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx.  If nCode is greater than or equal to zero, it is highly recommended that you call CallNextHookEx and return the value it returns; otherwise, other applications that have installed WH_CALLWNDPROC hooks will not receive hook notifications and may behave incorrectly as a result. If the hook procedure does not call CallNextHookEx, the return value should be zero.

如果nCode小于0,钩子子程必须返回由CallNextHookE方法返回的返回值。如果nCode大于等于0,强烈要求调用CallNextHookEx方法,并返回由它返回的返回值;否则,其他已经安装了WH_CALLWNDPROC钩子的应用程序将收不到钩子通知,可能导致行为的错误。如果钩子子程没有调用CallNextHookEx方法,返回值应该为 0

Remarks 备注

The CallWndProc hook procedure can examine the message, but it cannot modify it. After the hook procedure returns control to the system, the message is passed to the window procedure.

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

CallWndProc钩子子程能够检查消息,但是不能修改消息。当钩子子程将控制权交还给系统之后,消息被传递给窗体程序。

应用程序这样安装钩子子程:指定WH_CALLWNDPROC钩子类型,指定一个指向调用SetWindowsHookEx方法的钩子子程的指针。

方法4 CallWndRetProc Function

The CallWndRetProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function after the SendMessage function is called. The hook procedure can examine the message; it cannot modify it.

CallWndRetProc钩子子程是与SetWindowsHookEx一起使用的、用户定义的或者库定义的回调函数。在SendMessage方法被调用之后,系统调用CallWndRetProc方法。钩子子程能够检查、但是不能修改消息。

The HOOKPROC type defines a pointer to this callback function. CallWndRetProc is a placeholder for the application-defined or library-defined function name.

HOOKPROC类型定义了指向该回调函数的指针。CallWndRetProc是程序定义的或者库定义的方法名字。

Syntax 语法

LRESULT CALLBACK CallWndRetProc(      
        int nCode,

    WPARAM wParam,

    LPARAM lParam

);

Parameters 参数

nCode [in] Specifies whether the hook procedure must process the message. If nCode is HC_ACTION, the hook procedure must process the message. If nCode is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by CallNextHookEx.

指定钩子子程是否必须处理消息。如果nCodeHC_ACTION,钩子子程必须处理该消息。如果nCode小于0,钩子子程就必须将该消息传递给CallNextHookEx方法,自己不对消息进行进一步的处理,必须返回由CallNextHookEx 方法返回的返回值。

wParam [in] Specifies whether the message is sent by the current process. If the message is sent by the current process, it is nonzero; otherwise, it is NULL. 指定消息是否由当前进程发出。如果消息是由当前进程发出的,wParam为非0;否则,为空。

lParam [in] Pointer to a CWPRETSTRUCT structure that contains details about the message. 指向CWPSTRUCT结构的指针,该结构含有消息的细节信息。

Return Value 返回值

If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx.  If nCode is greater than or equal to zero, it is highly recommended that you call CallNextHookEx and return the value it returns; otherwise, other applications that have installed WH_CALLWNDPROCRET hooks will not receive hook notifications and may behave incorrectly as a result. If the hook procedure does not call CallNextHookEx, the return value should be zero.

如果nCode小于0,钩子子程必须返回由CallNextHookE返回的返回值。如果nCode大于等于0,强烈要求调用CallNextHookEx方法,并返回由它返回的返回值;否则,其他已经安装了WH_ CALLWNDPROCRET钩子的程序将收不到钩子通知,可能导致行为的错误。如果钩子子程没有调用CallNextHookEx方法,返回值应该为0

Remarks 备注

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

应用程序这样安装钩子子程:指定WH_ CALLWNDPROCRET钩子类型,指定一个指向调用SetWindowsHookEx方法的钩子子程的指针。

                        Helios 2007-04-12

赞助商链接

热门内容

相关内容

联系我们

联系方式