您的位置:首页 > 其它

SetWindowsHookEx 详解(三)

2014-09-28 17:05 369 查看
类型: 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.
ValueMeaning
HC_ACTION0
The wParam and lParam parameters contain information about a mouse message.
HC_NOREMOVE3
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: [b]LRESULT[/b]

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.
ValueMeaning
HC_ACTION0
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_LBUTTONDOWN, WM_LBUTTONUP,WM_MOUSEMOVE, WM_MOUSEWHEEL, WM_MOUSEHWHEEL,WM_RBUTTONDOWN,
or WM_RBUTTONUP.
lParam [in]

Type: LPARAM

A pointer to an MSLLHOOKSTRUCT structure.


Return value

Type:

Type: [b]LRESULT[/b]

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.
ValueMeaning
MSGF_DDEMGR0x8001
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_DIALOGBOX0
The input event occurred in a message box or dialog box.
MSGF_MENU2
The input event occurred in a menu.
MSGF_SCROLLBAR5
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: [b]LRESULT[/b]

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.
ValueMeaning
HSHELL_ACCESSIBILITYSTATE11
The accessibility state has changed.
HSHELL_ACTIVATESHELLWINDOW3
The shell should activate its main window.
HSHELL_APPCOMMAND12
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_GETMINRECT5
A window is being minimized or maximized. The system needs the coordinates of the minimized rectangle for the window.
HSHELL_LANGUAGE8
Keyboard language was changed or a new keyboard layout was loaded.
HSHELL_REDRAW6
The title of a window in the task bar has been redrawn.
HSHELL_TASKMAN7
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_WINDOWACTIVATED4
The activation has changed to a different top-level, unowned window.
HSHELL_WINDOWCREATED1
A top-level, unowned window has been created. The window exists when the system calls this hook.
HSHELL_WINDOWDESTROYED2
A top-level, unowned window is about to be destroyed. The window still exists when the system calls this hook.
HSHELL_WINDOWREPLACED13
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.
nCodewParam
HSHELL_ACCESSIBILITYSTATEIndicates which accessibility feature has changed state. This value is one of the following:ACCESS_FILTERKEYS,ACCESS_MOUSEKEYS, orACCESS_STICKYKEYS.
HSHELL_APPCOMMANDIndicates where theWM_APPCOMMAND message
was originally sent; for example, the handle to a window. For more information, see cmd parameter inWM_APPCOMMAND.
HSHELL_GETMINRECTA handle to the minimized or maximized window.
HSHELL_LANGUAGEA handle to the window.
HSHELL_REDRAWA handle to the redrawn window.
HSHELL_WINDOWACTIVATEDA handle to the activated window.
HSHELL_WINDOWCREATEDA handle to the created window.
HSHELL_WINDOWDESTROYEDA handle to the destroyed window.
HSHELL_WINDOWREPLACEDA 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.
nCodelParam
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_GETMINRECTA pointer to a RECT structure.
HSHELL_LANGUAGEA handle to a keyboard layout.
HSHELL_MONITORCHANGEDA handle to the window that moved to a different monitor.
HSHELL_REDRAWThe value is TRUE if the window is flashing, or FALSE otherwise.
HSHELL_WINDOWACTIVATEDThe value is TRUE if the window is in full-screen mode, or FALSEotherwise.
HSHELL_WINDOWREPLACEDA handle to the new window.

Windows 2000: Not supported.


Return value

Type:

Type: [b]LRESULT[/b]

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.
ValueMeaning
MSGF_DIALOGBOX0
The input event occurred in a message box or dialog box.
MSGF_MENU2
The input event occurred in a menu.
MSGF_SCROLLBAR5
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: [b]LRESULT[/b]

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)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: