LRESULT CALLBACK CBTProc(nCode, wParam, lParam) | |||||
int nCode; | /* CBT hook code | */ | |||
WPARAM wParam; | /* depends on the nCode parameter | */ | |||
LPARAM lParam; | /* depends on the nCode parameter | */ |
The CBTProc function is an application- or library-defined callback function that the system calls before performing any of the following operations:
Activating a window.
Creating or destroying a window.
Minimizing or maximizing a window.
Moving or sizing a window.
Completing a system command.
Removing a mouse or keyboard event from the system message queue.
Setting the input focus.
Synchronizing with the system message queue.
The value returned by the callback function determines whether to allow or prevent the operation.
nCode
Specifies a CBT hook code that identifies the operation about to be carried out, or a value less than zero if the callback function should pass the nCode, wParam, and lParam parameters to the CallNextHookEx function. The following list describes the CBT hook codes:
Code | Meaning |
HCBT_ACTIVATE | Indicates that the system is about to activate a window. |
HCBT_CLICKSKIPPED | Indicates that the system has removed a mouse message from the system message queue. A CBT application that needs to install a journaling playback filter in response to the mouse message should do so when it receives this hook code. |
HCBT_CREATEWND | Indicates that a window is about to be created. The system calls the callback function before sending the WM_CREATE message to the window. If the callback function returns TRUE, the system will destroy the window—the system will not send the WM_DESTROY message to the window. |
HCBT_DESTROYWND | Indicates that a window is about to be destroyed. |
HCBT_KEYSKIPPED | Indicates that the system has removed a keyboard message from the system message queue. A CBT application that needs to install a journaling playback filter in response to the keyboard message should do so when it receives this hook code. |
HCBT_MINMAX | Indicates that a window is about to be minimized or maximized. |
HCBT_MOVESIZE | Indicates that a window is about to be moved or sized. |
HCBT_QS | Indicates that the system has retrieved a WM_QUEUESYNC message from the system message queue. |
HCBT_SETFOCUS | Indicates that a window is about to receive the input focus. |
HCBT_SYSCOMMAND | Indicates that a system command is about to be carried out. This allows a CBT application to prevent task switching by hot keys. |
wParam
This parameter depends on the nCode parameter. See the following Comments section for details.
lParam
This parameter depends on the nCode parameter. See the following Comments section for details.
For operations corresponding to the following CBT hook codes, the callback function should return zero to allow the operation, or 1 to prevent it:
HCBT_ACTIVATE
HCBT_CREATEWND
HCBT_DESTROYWND
HCBT_MINMAX
HCBT_MOVESIZE
HCBT_SYSCOMMAND
The return value is ignored for operations corresponding to the following CBT hook codes:
HCBT_CLICKSKIPPED
HCBT_KEYSKIPPED
HCBT_QS
The callback function should not install a playback hook except in the situations described in the preceding list of hook codes.
An application must install the callback function by specifying the WH_CBT filter type and address of the callback function in a call to the SetWindowsHookEx function.
CBTProc is a placeholder for the application- or library-defined function name. The actual name must be exported by including it in the EXPORTS statement in a module-definition file.
The following table describes the wParam and lParam parameters for each HCBT_ constant.
Constant | wParam | lParam |
HCBT_ACTIVATE | Specifies the handle of the window about to be activated. | Specifies a long pointer to a CBTACTIVATE STRUCT structure that contains the handle of the currently active window and specifies whether the activation is changing because of a mouse click. |
HCBT_CLICKSKIPPED | Identifies the mouse message removed from the system message queue. | Specifies a long pointer to a MOUSEHOOK STRUCT structure that contains the hit-test code and the handle of the window for which the mouse message is intended. See the description of the WM_NCHITTEST message for a list of hit-test codes. |
HCBT_CREATEWND | Specifies the handle of the new window. | Specifies a long pointer to a CBT_CREATEWND data structure that contains initialization parameters for the window. |
HCBT_DESTROYWND | Specifies the handle of the window about to be destroyed. | This parameter is undefined; it should be set to 0L. |
HCBT_KEYSKIPPED | Identifies the virtual key code. | Specifies the repeat count, scan code, key-transition code, previous key state, and context code. See the description of the WM_KEYUP or WM_KEYDOWN message for more information. |
HCBT_MINMAX | Specifies the handle of the window being minimized or maximized. | The low-order word specifies a show-window value (SW_*) that specifies the operation. See the description of the ShowWindow function for a list of show-window values. The high-order word is undefined. |
HCBT_MOVESIZE | Specifies the handle of the window to be moved or sized. | Specifies a long pointer to a RECT structure that contains the coordinates of the window. |
HCBT_QS | This parameter is undefined; it should be set to 0. | This parameter is undefined; it should be set to 0L. |
HCBT_SETFOCUS | Specifies the handle of the window gaining the input focus. | The low-order word specifies the handle of the window losing the input focus. The high-order word is undefined. |
HCBT_SYSCOMMAND | Specifies a system-command value (SC_*) that specifies the system command. See the description of the WM_SYSCOMMAND message for more information about system command values. | If wParam is SC_HOTKEY, the low-order word contains the handle of the window that task switching will bring to the foreground; otherwise, wParam is undefined. |
CallNextHookEx, SetWindowsHookEx