CBTProc
The CBTProc
hook procedure is an application-defined or 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 keyboard focus; or before synchronizing with the system message
queue. The value returned by the hook procedure determines whether Windows
allows or prevents one of these operations. A computer-based training (CBT)
application uses this hook procedure to receive useful notifications from the
system.
LRESULT CALLBACK CBTProc(
int nCode, |
// hook code |
WPARAM wParam, |
// depends on hook
code |
LPARAM lParam |
// depends on hook
code |
); |
|
Parameters
nCode
Specifies a
code that the hook procedure uses to determine how to process the message. This
parameter can be one of the following values:
Value |
Meaning |
HCBT_ACTIVATE |
The system
is about to activate a window. |
HCBT_CLICKSKIPPED |
The system
has removed a mouse message from the system message queue. Upon receiving
this hook code, a CBT application must install a WH_JOURNALPLAYBACK hook |
HCBT_CREATEWND |
A window is
about to be created. The system calls the hook procedure before sending the WM_CREATE |
|
At the time
of the HCBT_CREATEWND notification, the window has been created, but its
final size and position may not have been determined and its parent window
may not have been established. It is possible to send messages to the newly
created window, although it has not yet received WM_NCCREATE or WM_CREATE
messages. It is also possible to change the position in the Z order of the
newly created window by modifying the hwndInsertAfter member of the CBT_CREATEWND |
HCBT_DESTROYWND |
A window is
about to be destroyed. |
HCBT_KEYSKIPPED |
The system
has removed a keyboard message from the system message queue. Upon receiving
this hook code, a CBT application must install a WH_JOURNALPLAYBACK_hook |
HCBT_MINMAX |
A window is
about to be minimized or maximized. |
HCBT_MOVESIZE |
A window is
about to be moved or sized. |
HCBT_QS |
The system
has retrieved a WM_QUEUESYNC |
HCBT_SETFOCUS |
A window is
about to receive the keyboard focus. |
HCBT_SYSCOMMAND |
A system
command is about to be carried out. This allows a CBT application to prevent
task switching by means of hot keys. |
If nCode
is less than zero, the hook procedure must pass the message to the CallNextHookEx
wParam
Depends on
the nCode parameter. For details, see the following Remarks section.
lParam
Depends on
the nCode parameter. For details, see the following Remarks section.
Return Values
For
operations corresponding to the following CBT hook codes, the return value must
be 0 to allow the operation, or 1 to prevent it:
HCBT_ACTIVATE
HCBT_CREATEWND
HCBT_DESTROYWND
HCBT_MINMAX
HCBT_MOVESIZE
HCBT_SETFOCUS
HCBT_SYSCOMMAND
For operations
corresponding to the following CBT hook codes, the return value is ignored:
HCBT_CLICKSKIPPED
HCBT_KEYSKIPPED
HCBT_QS
Remarks
The hook
procedure should not install a WH_JOURNALPLAYBACK_hook
This hook
procedure must be in a dynamic-link library (DLL). An application installs the
hook procedure by specifying the WH_CBT hook type and the address of the hook
procedure in a call to the SetWindowsHookEx
The following
table describes the wParam and lParam parameters for each HCBT_
hook code:
Value |
wParam |
lParam |
HCBT_ACTIVATE |
Specifies
the handle to the window about to be activated. |
Specifies a
long pointer to a CBTACTIVATESTRUCT |
HCBT_CLICKSKIPPED |
Identifies
the mouse message removed from the system message queue. |
Specifies a
long pointer to a MOUSEHOOKSTRUCT The
HCBT_CLICKSKIPPED value is sent to a CBTProc hook procedure only if a
WH_MOUSE hook is installed. For a list of hit-test codes, see WM_NCHITTEST |
HCBT_CREATEWND |
Specifies
the handle to the new window. |
Specifies a
long pointer to a CBT_CREATEWND |
HCBT_DESTROYWND |
Specifies
the handle to the window about to be destroyed. |
Is
undefined and must be set to zero. |
HCBT_KEYSKIPPED |
Identifies
the virtual-key code. |
Specifies
the repeat count, scan code, key-transition code, previous key state, and
context code. The HCBT_KEYSKIPPED value is sent to a CBTProc hook
procedure only if a WH_KEYBOARD hook is installed. For more information, see
the WM_KEYUP |
HCBT_MINMAX |
Specifies
the handle to the window being minimized or maximized. |
Specifies,
in the low-order word, a show-window value (SW_) specifying the operation.
For a list of show-window values, see the ShowWindow |
HCBT_MOVESIZE |
Specifies
the handle to the window to be moved or sized. |
Specifies a
long pointer to a RECT |
HCBT_QS |
Is
undefined and must be zero. |
Is
undefined and must be zero. |
HCBT_SETFOCUS |
Specifies
the handle to the window gaining the keyboard focus. |
Specifies
the handle to the window losing the keyboard focus. |
HCBT_SYSCOMMAND |
Specifies a
system-command value (SC_) specifying the system command. For more
information about system-command values, see WM_SYSCOMMAND |
Contains
the same data as the lParam value of a WM_SYSCOMMAND |
CBTProc is a placeholder for the application-defined or
library-defined function name.
See Also