CBTProc

3.1

  LRESULT CALLBACK CBTProc(code, wParam, lParam)    
  int code; /* CBT hook code, */  
  WPARAM wParam; /* depends on the code parameter */
  LPARAM lParam; /* depends on the code parameter */

The CBTProc function is a library-defined callback function that the system calls 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 input focus; or before synchronizing with the system message queue.

The value returned by the callback function determines whether to allow or prevent one of these operations.

Parameters

code

Specifies a computer-based-training (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 code, wParam, and lParam parameters to the CallNextHookEx function. The code parameter can be one of the following:

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 must 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 or WM_NCCREATE message to the window. If the callback function returns TRUE, the system destroys the window—the CreateWindow function returns NULL, but the WM_DESTROY message is not sent to the window. If the callback function returns FALSE, the window is created normally.
  At the time of the HCBT_CREATEWND notification, the window has been created, but its final size and position may not have been determined, nor has its parent window been established.
  It is possible to send messages to the newly created window, although the window has not yet received WM_NCCREATE or WM_CREATE messages.
  It is possible to change the Z-order of the newly created window by modifying the hwndInsertAfter member of the CBT_CREATEWND structure.
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 must 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 code parameter. See the following Comments section for details.

lParam

This parameter depends on the code parameter. See the following Comments section for details.

Return Value

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

Comments

The callback function should not install a playback hook except in the situations described in the preceding list of hook codes.

This callback function must be in a dynamic-link library.

An application must install the callback function by specifying the WH_CBT filter type and the procedure-instance address of the callback function in a call to the SetWindowsHookEx function.

CBTProc is a placeholder for the library-defined function name. The actual name must be exported by including it in an EXPORTS statement in the library's 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 CBTACTIVATESTRUCT 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 MOUSEHOOKSTRUCT structure that contains the hit-test code and the handle of the window for which the mouse message is intended. For a list of hit-test codes, see the description of the WM_NCHITTEST message.
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 and 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. For more information, see the description of the WM_KEYUP or WM_KEYDOWN message.
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. For a list of show-window values, see the description of the ShowWindow function. 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 and 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. For more information about system command values, see the description of the WM_SYSCOMMAND message. If wParam is SC_HOTKEY, the low-order word of lParam contains the handle of the window that task switching will bring to the foreground. If wParam is not SC_HOTKEY and a System-menu command is chosen with the mouse, the low-order word of lParam contains the x-coordinate of the cursor and the high-order word contains the y-coordinate. If neither of these conditions is true, lParam is undefined.

See Also

CallNextHookEx, SetWindowsHookEx