钩子初接触(二十)

来源:互联网 发布:好用的ftp工具 知乎 编辑:程序博客网 时间:2024/05/02 08:26

方法15 :MouseProc Function

The MouseProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function whenever an application calls the GetMessage or PeekMessage function and there is a mouse message to be processed. MouseProc钩子子程是同SetWindowsHookEx方法一起使用的、应用程序定义的或者库定义的回调函数。无论什么时候,当应用程序一调用GetMessage 或者 PeekMessage方法,有鼠标消息即将被处理时,系统调用该方法。

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

Syntax:语法

LRESULT CALLBACK MouseProc(      

         int nCode,
    WPARAM wParam,
    LPARAM lParam
);

Parameters 参数

nCode [in] Specifies a code the hook procedure uses to determine how to 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. This parameter can be one of the following values. 指定钩子子程使用的用来决定如何处理消息的码值。如果nCode小于0,钩子子程必须将消息传递给CallNextHookEx方法,自己不进行进一步的处理,并且要返回由CallNextHookEx方法返回的返回值。该参数可以是下列值之一:

1HC_ACTION The wParam and lParam parameters contain information about a mouse message. 参数wParam lParam包含和鼠标消息相关的信息。

2HC_NOREMOVE The wParam and lParam parameters contain information about a mouse message, and the mouse message has not been removed from the message queue. (An application called the PeekMessage function, specifying the PM_NOREMOVE flag.)

参数wParam lParam包含和鼠标消息相关的信息,鼠标消息还没有从消息队列中移除。

wParam [in] Specifies the identifier of the mouse message. 指定鼠标消息的标识符。

lParam[in] Pointer to a MOUSEHOOKSTRUCT structure. 指向MOUSEHOOKSTRUCT结构的指针。

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, 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_MOUSE 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 target window procedure.

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

Remarks备注

An application installs the hook procedure by specifying the WH_MOUSE hook type and a pointer to the hook procedure in a call to the SetWindowsHookEx function. The hook procedure must not install a WH_JOURNALPLAYBACK Hook callback function.

应用程序通过下面方法来安装钩子:指定WH_MOUSE钩子类型;指定在调用SetWindowsHookEx的方法中指向钩子子程的指针。该钩子子程不应安装WH_JOURNALPLAYBACK钩子的回调函数。

Helios  2007-4-29