Click to Rate and Give Feedback
MSDN
MSDN Library
User Interface
Windowing
Hooks
Hooks
A hook is a point in the system message-handling mechanism where an application can install a subroutine to monitor the message traffic in the system and process certain types of messages before they reach the target window procedure.

Overviews

About Hooks

This topic discusses how hooks should be used.

Using Hooks

The following code examples demonstrate how to perform the following tasks associated with hooks.

Functions

CallMsgFilter

The CallMsgFilter function passes the specified message and hook code to the hook procedures associated with the WH_SYSMSGFILTER and WH_MSGFILTER hooks. A WH_SYSMSGFILTER or WH_MSGFILTER hook procedure is an application-defined callback function that examines and, optionally, modifies messages for a dialog box, message box, menu, or scroll bar.

CallNextHookEx

The CallNextHookEx function passes the hook information to the next hook procedure in the current hook chain. A hook procedure can call this function either before or after processing the hook information.

CallWndProc

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

  • Windows 95/98/Me, Windows NT 3.51: The system calls this function whenever the thread calls the SendMessage function. The WH_CALLWNDPROC hook is called in the context of the thread that calls SendMessage, not the thread that receives the message.
  • Windows NT 4.0 and later: The system calls this function before calling the window procedure to process a message sent to the thread.

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

CallWndRetProc

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.

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

CBTProc

The CBTProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function before activating, creating, destroying, minimizing, maximizing, moving, or sizing a window; before completing a system command; before removing a mouse or keyboard event from the system message queue; before setting the keyboard focus; or before synchronizing with the system message queue. A computer-based training (CBT) application uses this hook procedure to receive useful notifications from the system.

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

DebugProc

The DebugProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function before calling the hook procedures associated with any type of hook. The system passes information about the hook to be called to the DebugProc hook procedure, which examines the information and determines whether to allow the hook to be called.

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

ForegroundIdleProc

The ForegroundIdleProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function whenever the foreground thread is about to become idle.

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

GetMsgProc

The GetMsgProc function is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function whenever the GetMessage or PeekMessage function has retrieved a message from an application message queue. Before returning the retrieved message to the caller, the system passes the message to the hook procedure.

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

JournalPlaybackProc

The JournalPlaybackProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. Typically, an application uses this function to play back a series of mouse and keyboard messages recorded previously by the JournalRecordProc hook procedure. As long as a JournalPlaybackProc hook procedure is installed, regular mouse and keyboard input is disabled.

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

JournalRecordProc

The JournalRecordProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The function records messages the system removes from the system message queue. Later, an application can use a JournalPlaybackProc hook procedure to play back the messages.

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

KeyboardProc

The KeyboardProc 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 keyboard message (WM_KEYUP or WM_KEYDOWN) to be processed.

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

LowLevelKeyboardProc

The LowLevelKeyboardProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function every time a new keyboard input event is about to be posted into a thread input queue. The keyboard input can come from the local keyboard driver or from calls to the keybd_event function. If the input comes from a call to keybd_event, the input was "injected". However, the WH_KEYBOARD_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 HOOKPROC type defines a pointer to this callback function. LowLevelKeyboardProc is a placeholder for the application-defined or library-defined function name.

LowLevelMouseProc

The LowLevelMouseProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system call this function every time a new mouse input event is about to be posted into a thread input queue. The mouse input can come from the local mouse driver or from calls to the mouse_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 HOOKPROC type defines a pointer to this callback function. LowLevelMouseProc is a placeholder for the application-defined or library-defined function name.

MessageProc

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.

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

MouseProc

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.

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

SetWindowsHookEx

The SetWindowsHookEx function installs an application-defined hook procedure into a hook chain. You would install a hook procedure to monitor the system for certain types of events. These events are associated either with a specific thread or with all threads in the same desktop as the calling thread.

ShellProc

The ShellProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx 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.

SysMsgProc

The SysMsgProc hook procedure is a 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 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.

UnhookWindowsHookEx

The UnhookWindowsHookEx function removes a hook procedure installed in a hook chain by the SetWindowsHookEx function.

Notifications

WM_CANCELJOURNAL

The WM_CANCELJOURNAL message is posted to an application when a user cancels the application's journaling activities. The message is posted with a NULL window handle.

WM_QUEUESYNC

The WM_QUEUESYNC message is sent by a CBT application to separate user-input messages from other messages sent through the WH_JOURNALPLAYBACK Hook procedure.

Structures

CBT_CREATEWND

The CBT_CREATEWND structure contains information passed to a WH_CBT hook procedure, CBTProc, before a window is created.

CBTACTIVATESTRUCT

The CBTACTIVATESTRUCT structure contains information passed to a WH_CBT hook procedure, CBTProc, before a window is activated.

CWPRETSTRUCT

The CWPRETSTRUCT structure defines the message parameters passed to a WH_CALLWNDPROCRET hook procedure, CallWndRetProc.

CWPSTRUCT

The CWPSTRUCT structure defines the message parameters passed to a WH_CALLWNDPROC hook procedure, CallWndProc.

DEBUGHOOKINFO

The DEBUGHOOKINFO structure contains debugging information passed to a WH_DEBUG hook procedure, DebugProc.

EVENTMSG

The EVENTMSG structure contains information about a hardware message sent to the system message queue. This structure is used to store message information for the JournalPlaybackProc callback function.

KBDLLHOOKSTRUCT

The KBDLLHOOKSTRUCT structure contains information about a low-level keyboard input event.

MOUSEHOOKSTRUCT

The MOUSEHOOKSTRUCT structure contains information about a mouse event passed to a WH_MOUSE hook procedure, MouseProc.

MOUSEHOOKSTRUCTEX

The MOUSEHOOKSTRUCTEX structure contains information about a mouse event passed to a WH_MOUSE hook procedure, MouseProc.

This is an extension of the MOUSEHOOKSTRUCT structure that includes information about wheel movement or the use of the X button.

MSLLHOOKSTRUCT

The MSLLHOOKSTRUCT structure contains information about a low-level keyboard input event.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content      
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker