SetWindowsHookEx 详解(三)

类型: WH_MOUSE值7,回调参数如下

MouseProc callback function

An application-defined or library-defined callback function used with theSetWindowsHookEx function. The system calls this function whenever an application calls the GetMessage or PeekMessage function and there is a mouse message to be processed.

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

Syntax

C++
LRESULT CALLBACK MouseProc(
  _In_  int nCode,
  _In_  WPARAM wParam,
  _In_  LPARAM lParam
);

Parameters

nCode [in]

Type: int

A code that 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.

Value Meaning
HC_ACTION 0

The wParam and lParam parameters contain information about a mouse message.

HC_NOREMOVE 3

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 thePeekMessage function, specifying thePM_NOREMOVE flag.)

 

wParam [in]

Type: WPARAM

The identifier of the mouse message.

lParam [in]

Type: LPARAM

A pointer to a MOUSEHOOKSTRUCT structure.

Return value

Type:

Type: LRESULT

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 CallNextHookExand return the value it returns; otherwise, other applications that have installedWH_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.

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 SetWindowsHookExfunction.

The hook procedure must not install a WH_JOURNALPLAYBACK callback function.

This hook may be called in the context of the thread that installed it. The call is made by sending a message to the thread that installed the hook. Therefore, the thread that installed the hook must have a message loop.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

类型:  WH_MOUSE_LL值14,回调参数如下

LowLevelMouseProc callback function

An application-defined or library-defined callback function used with theSetWindowsHookEx function. The system calls this function every time a new mouse input event is about to be posted into a thread input queue.

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

Syntax

C++
LRESULT CALLBACK LowLevelMouseProc(
  _In_  int nCode,
  _In_  WPARAM wParam,
  _In_  LPARAM lParam
);

Parameters

nCode [in]

Type: int

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.

Value Meaning
HC_ACTION 0

The wParam and lParam parameters contain information about a mouse message.

 

wParam [in]

Type: WPARAM

The identifier of the mouse message. This parameter can be one of the following messages: WM_LBUTTONDOWNWM_LBUTTONUP,WM_MOUSEMOVEWM_MOUSEWHEELWM_MOUSEHWHEEL,WM_RBUTTONDOWN, or WM_RBUTTONUP.

lParam [in]

Type: LPARAM

A pointer to an MSLLHOOKSTRUCT structure.

Return value

Type:

Type: LRESULT

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 CallNextHookExand return the value it returns; otherwise, other applications that have installedWH_MOUSE_LL 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.

Remarks

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

This hook is called in the context of the thread that installed it. The call is made by sending a message to the thread that installed the hook. Therefore, the thread that installed the hook must have a message loop.

The mouse input can come from the local mouse driver or from calls to themouse_event function. If the input comes from a call to mouse_event, the input was "injected". However, the WH_MOUSE_LL hook is not injected into another process. Instead, the context switches back to the process that installed the hook and it is called in its original context. Then the context switches back to the application that generated the event.

The hook procedure should process a message in less time than the data entry specified in the LowLevelHooksTimeout value in the following registry key:

HKEY_CURRENT_USER\Control Panel\Desktop

The value is in milliseconds. If the hook procedure times out, the system passes the message to the next hook. However, on Windows 7 and later, the hook is silently removed without being called. There is no way for the application to know whether the hook is removed.

Note  Debug hooks cannot track this type of low level mouse hooks. If the application must use low level hooks, it should run the hooks on a dedicated thread that passes the work off to a worker thread and then immediately returns. In most cases where the application needs to use low level hooks, it should monitor raw input instead. This is because raw input can asynchronously monitor mouse and keyboard messages that are targeted for other threads more effectively than low level hooks can. For more information on raw input, see Raw Input.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

类型:  WH_MSGFILTER值-1,回调参数如下

MessageProc callback function

An application-defined or library-defined callback function used with theSetWindowsHookEx 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.

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

Syntax

C++
LRESULT CALLBACK MessageProc(
  _In_  int code,
  WPARAM wParam,
  _In_  LPARAM lParam
);

Parameters

code [in]

Type: int

The type of input event that generated the message. If code is less than zero, the hook procedure must pass the message to the CallNextHookExfunction without further processing and return the value returned byCallNextHookEx. This parameter can be one of the following values.

Value Meaning
MSGF_DDEMGR 0x8001

The input event occurred while the DDEML was waiting for a synchronous transaction to finish. For more information about DDEML, seeDynamic Data Exchange Management Library.

MSGF_DIALOGBOX 0

The input event occurred in a message box or dialog box.

MSGF_MENU 2

The input event occurred in a menu.

MSGF_SCROLLBAR 5

The input event occurred in a scroll bar.

 

wParam

Type: WPARAM

This parameter is not used.

lParam [in]

Type: LPARAM

A pointer to an MSG structure.

Return value

Type:

Type: LRESULT

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 installedWH_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.

Remarks

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

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

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

类型:  WH_SHELL值10,回调参数如下

ShellProc callback function

An application-defined or library-defined callback function used with theSetWindowsHookEx function. The function receives notifications of Shell events from the system.

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

Syntax

C++
LRESULT CALLBACK ShellProc(
  _In_  int nCode,
  _In_  WPARAM wParam,
  _In_  LPARAM lParam
);

Parameters

nCode [in]

Type: int

The hook code. 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.

Value Meaning
HSHELL_ACCESSIBILITYSTATE 11

The accessibility state has changed.

HSHELL_ACTIVATESHELLWINDOW 3

The shell should activate its main window.

HSHELL_APPCOMMAND 12

The user completed an input event (for example, pressed an application command button on the mouse or an application command key on the keyboard), and the application did not handle theWM_APPCOMMANDmessage generated by that input.

If the Shell procedure handles the WM_COMMANDmessage, it should not callCallNextHookEx. See the Return Value section for more information.

HSHELL_GETMINRECT 5

A window is being minimized or maximized. The system needs the coordinates of the minimized rectangle for the window.

HSHELL_LANGUAGE 8

Keyboard language was changed or a new keyboard layout was loaded.

HSHELL_REDRAW 6

The title of a window in the task bar has been redrawn.

HSHELL_TASKMAN 7

The user has selected the task list. A shell application that provides a task list should return TRUE to prevent Windows from starting its task list.

HSHELL_WINDOWACTIVATED 4

The activation has changed to a different top-level, unowned window.

HSHELL_WINDOWCREATED 1

A top-level, unowned window has been created. The window exists when the system calls this hook.

HSHELL_WINDOWDESTROYED 2

A top-level, unowned window is about to be destroyed. The window still exists when the system calls this hook.

HSHELL_WINDOWREPLACED 13

A top-level window is being replaced. The window exists when the system calls this hook.

 

wParam [in]

Type: WPARAM

This parameter depends on the value of the nCode parameter, as shown in the following table.

nCode wParam
HSHELL_ACCESSIBILITYSTATE Indicates which accessibility feature has changed state. This value is one of the following:ACCESS_FILTERKEYS,ACCESS_MOUSEKEYS, orACCESS_STICKYKEYS.
HSHELL_APPCOMMAND Indicates where theWM_APPCOMMAND message was originally sent; for example, the handle to a window. For more information, see cmd parameter inWM_APPCOMMAND.
HSHELL_GETMINRECT A handle to the minimized or maximized window.
HSHELL_LANGUAGE A handle to the window.
HSHELL_REDRAW A handle to the redrawn window.
HSHELL_WINDOWACTIVATED A handle to the activated window.
HSHELL_WINDOWCREATED A handle to the created window.
HSHELL_WINDOWDESTROYED A handle to the destroyed window.
HSHELL_WINDOWREPLACED A handle to the window being replaced.

Windows 2000:  Not supported.

 

lParam [in]

Type: LPARAM

This parameter depends on the value of the nCode parameter, as shown in the following table.

nCode lParam
HSHELL_APPCOMMAND

GET_APPCOMMAND_LPARAM(lParam) is the application command corresponding to the input event.

GET_DEVICE_LPARAM(lParam) indicates what generated the input event; for example, the mouse or keyboard. For more information, see theuDevice parameter description under WM_APPCOMMAND.

GET_FLAGS_LPARAM(lParam) depends on the value of cmd inWM_APPCOMMAND. For example, it might indicate which virtual keys were held down when theWM_APPCOMMAND message was originally sent. For more information, see the dwCmdFlagsdescription parameter underWM_APPCOMMAND.

HSHELL_GETMINRECT A pointer to a RECT structure.
HSHELL_LANGUAGE A handle to a keyboard layout.
HSHELL_MONITORCHANGED A handle to the window that moved to a different monitor.
HSHELL_REDRAW The value is TRUE if the window is flashing, or FALSE otherwise.
HSHELL_WINDOWACTIVATED The value is TRUE if the window is in full-screen mode, or FALSEotherwise.
HSHELL_WINDOWREPLACED A handle to the new window.

Windows 2000:  Not supported.

 

Return value

Type:

Type: LRESULT

The return value should be zero unless the value of nCode isHSHELL_APPCOMMAND and the shell procedure handles theWM_COMMAND message. In this case, the return should be nonzero.

Remarks

Install this hook procedure by specifying the WH_SHELL hook type and a pointer to the hook procedure in a call to the SetWindowsHookEx function.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

类型:  WH_SYSMSGFILTER值6,回调参数如下

SysMsgProc callback function

An application-defined or library-defined callback function used with theSetWindowsHookEx 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 function can monitor messages for any dialog box, message box, menu, or scroll bar in the system.

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

Syntax

C++
LRESULT CALLBACK SysMsgProc(
  _In_  int nCode,
  WPARAM wParam,
  _In_  LPARAM lParam
);

Parameters

nCode [in]

Type: int

The type of input event that generated the message. If nCode is less than zero, the hook procedure must pass the message to theCallNextHookEx function without further processing and should return the value returned by CallNextHookEx. This parameter can be one of the following values.

Value Meaning
MSGF_DIALOGBOX 0

The input event occurred in a message box or dialog box.

MSGF_MENU 2

The input event occurred in a menu.

MSGF_SCROLLBAR 5

The input event occurred in a scroll bar.

 

wParam

Type: WPARAM

This parameter is not used.

lParam [in]

Type: LPARAM

A pointer to an MSG message structure.

Return value

Type:

Type: LRESULT

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 CallNextHookExand return the value it returns; otherwise, other applications that have installedWH_SYSMSGFILTER 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.

Remarks

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

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值