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.

In This Section

Name Description
Hook Overview Discusses how hooks should be used.
Using Hooks Demonstrates how to perform tasks associated with hooks.
Hook Reference Contains the API reference.

Hook Functions

Name Description
CallMsgFilter Passes the specified message and hook code to the hook procedures associated with the WH_SYSMSGFILTER and WH_MSGFILTER hook procedures.
CallNextHookEx 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 An application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function before calling the window procedure to process a message sent to the thread.
CallWndRetProc 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.
CBTProc 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.
DebugProc 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.
ForegroundIdleProc 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.
GetMsgProc 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.
JournalPlaybackProc 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.
JournalRecordProc 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.
KeyboardProc 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.
LowLevelKeyboardProc 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.
LowLevelMouseProc An application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function every time a new mouse input event is about to be posted into a thread input queue.
MessageProc 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.
MouseProc 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.
SetWindowsHookEx 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 An application-defined or library-defined callback function used with the SetWindowsHookEx function. The function receives notifications of Shell events from the system.
SysMsgProc 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 function can monitor messages for any dialog box, message box, menu, or scroll bar in the system.
UnhookWindowsHookEx Removes a hook procedure installed in a hook chain by the SetWindowsHookEx function.

Hook Notifications

Name Description
WM_CANCELJOURNAL Posted to an application when a user cancels the application's journaling activities. The message is posted with a NULL window handle.
WM_QUEUESYNC Sent by a CBT application to separate user-input messages from other messages sent through the WH_JOURNALPLAYBACK procedure.

Hook Structures

Name Description
CBT_CREATEWND Contains information passed to a WH_CBT hook procedure, CBTProc, before a window is created.
CBTACTIVATESTRUCT Contains information passed to a WH_CBT hook procedure, CBTProc, before a window is activated.
CWPRETSTRUCT Defines the message parameters passed to a WH_CALLWNDPROCRET hook procedure, CallWndRetProc.
CWPSTRUCT Defines the message parameters passed to a WH_CALLWNDPROC hook procedure, CallWndProc.
DEBUGHOOKINFO Contains debugging information passed to a WH_DEBUG hook procedure, DebugProc.
EVENTMSG 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 Contains information about a low-level keyboard input event.
MOUSEHOOKSTRUCT Contains information about a mouse event passed to a WH_MOUSE hook procedure, MouseProc.
MOUSEHOOKSTRUCTEX Contains information about a mouse event passed to a WH_MOUSE hook procedure, MouseProc.
MSLLHOOKSTRUCT Contains information about a low-level mouse input event.

SetWinEventHook