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.
CBTProc钩子程序是一个在应用程序定义或者是在库定义的与SetWindowHookEx合作使用的回调函数。系统在激活,建立,销毁,最小化,最大化,移动或者是改变窗口大小之前;在完成一个系统命令之前;在从系统消息队列里移除鼠标或者键盘事件之前;在设置键盘焦点之前;或者在和系统消息队列同步之前呼叫这个函数。一个CBT应用程序使用这个钩子程序来从系统接受有用的通知。
The HOOKPROC type defines a pointer to this callback function. CBTProc is a placeholder for the application-defined or library-defined function name.
HOOKPROC类型定义了一个指向回调函数的指针。CBTProc是一个为在应用程序定义或者是在库定义的函数名字的占位符。
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 procedure in response to the mouse message.
(系统已经从系统消息队列删除了一条鼠标消息。为了处理这个钩子代码,CBT应用程序必须安装了WH_JOURNALPLAYBACK钩子程序来回应这条鼠标消息。
HCBT_CREATEWND A window is about to be created. The system calls the hook procedure before sending theWM_CREATE orWM_NCCREATE message to the window. If the hook procedure returns a nonzero value, the system destroys the window; theCreateWindow function returns NULL, but theWM_DESTROY message is not sent to the window. If the hook procedure returns zero, 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 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 structure.
(窗口将被激活。在发送WM_CREAT或者是WM_NCCREATE消息给窗口之前,系统将会呼叫这个钩子程序。如果钩子程序返回了一个非0值,系统将会销毁窗口;CreateWindow函数返回NULL,但是WM_DESTROY消息不会发送给窗口。如果钩子程序返回0,那么窗口将被正常创建。
在HCBT_CREATEWND通知的同时,窗口将被创建,但是他的最终大小和位置不确定,并且它的父窗口很可能没有被建立。很可能,消息发送给了新建的窗口,尽管这个窗口并没有收到WM_NCCREATE或者是WM_CREATE消息。也有可能,通过更改CBT_CREATEWND结构的hwndInsertAfter成员,改变了新建窗口的Z命令的地方。
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 hook procedure in response to the keyboard message.
系统从系统消息队列里删除了键盘消息。为了收到这个钩子代码,CBT应用程序必须安装一个处理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 message from the system message queue.
系统从系统消息队列中检索了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.
将被执行的系统命令。这个值会允许CBT应用程序通过热键的方式来阻止任务切换。
If nCode is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by CallNextHookEx.
如果nCode小于0,这个钩子程序未经进一步处理,直接把消息传递给CallNextHookEx函数,然后返回CallNextHookEx返回的值。
wParam
Depends on the nCode parameter. For details, see the following Remarks section.
依赖于nCode参数。想了解更多细节,参考下面的Remarks一节。
lParam
Depends on the nCode parameter. For details, see the following Remarks section.
依赖于nCode参数,想了解更多细节,参考下面Remarks一节。
Return Values(返回值)
The value returned by the hook procedure determines whether the system allows or prevents one of these operations. For operations corresponding to the following CBT hook codes, the return value must be 0 to allow the operation, or 1 to prevent it:
从钩子程序返回的值决定了系统是否允许或者阻止这些操作中的某一个。对与下面的CBT钩子代码呼应的操作来说,返回值必须为0来允许操作,或者为1来阻止操作。
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:
对响应下面的CBT钩子代码的操作来说,返回值就被忽略了:
HCBT_CLICKSKIPPED
HCBT_KEYSKIPPED
HCBT_QS
Remarks
The hook procedure should not install a WH_JOURNALPLAYBACK_hook hook procedure except in the situations described in the preceding list of hook codes.
钩子程序不应该安装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 function.
这个钩子程序必须在DLL里。一个应用程序通过指明WH_CBT钩子类型和呼叫SetWindowsHookEx函数的钩子过程的地址来安装钩子程序。
The following table describes the wParam and lParam parameters for each HCBT_ hook code:
下面的表描述了每个HCBT_hook代码的wParam和lParam参数
Value wParam lParam
HCBT_ACTIVATE Specifies the handle to the window about to be activated. (指明了将被激活的窗口的句柄) Specifies a long pointer to a CBTACTIVATESTRUCT structure containing the handle to the active window and specifies whether the activation is changing because of a mouse click.(指明了一个指向CBTACTIVATESTRUCT结构(包含了活动窗口的句柄)的long指针,并且指明了是否因鼠标点击而改变动作)
HCBT_CLICKSKIPPED Identifies the mouse message removed from the system message queue.(标识从系统消息队列里删除的鼠标消息) Specifies a long pointer to a MOUSEHOOKSTRUCT structure containing the hit-test code and the handle to the window for which the mouse message is intended.
(指明一个指向MOUSEHOOKSTRUCT结构(包含了命中测试代码和接收鼠标消息的窗口句柄)的long指针)
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, seeWM_NCHITTEST. (HCBT_CLICKSIPPED值会被送往CBTProc钩子程序,除非安装了WH_MOUSE钩子。想了解命中测试代码详细列表,参考WM_NCHITTEST)
HCBT_CREATEWND Specifies the handle to the new window.(指明了新窗口的句柄) Specifies a long pointer to a CBT_CREATEWND structure containing initialization parameters for the window.(指明一个指向CBT_CREATWND结构(包含了这个窗口的初始化参数)的long指针) The parameters include the coordinates and dimensions of the window.(这个参数包含了窗口的坐标和大小) By changing these parameters, a CBTProc hook procedure can set the initial size and position of the window.(通过更改这些参数,CBTProc钩子程序可以设置窗口的初始化大小和位置。
HCBT_DESTROYWND Specifies the handle to the window about to be destroyed.(指明将被销毁的窗口的句柄) Is undefined and must be set to zero. (未定义,必须被设置为0)
HCBT_KEYSKIPPED Identifies the virtual-key code(标识虚拟码). Specifies the repeat count, scan code, key-transition code, previous key state, and context code(指明重复次数,扫描码,翻译码,先前key(按键)的状态和码的内容). The HCBT_KEYSKIPPED value is sent to a CBTProc hook procedure only if a WH_KEYBOARD hook is installed(除非安装了WH_KEYBOARD钩子,HCBT_KEYSKIPPED才会被送往CBTProc钩子程序). For more information, seeWM_KEYUP orWM_KEYDOWN. (想了解更多,参考WM_KEYUP或者是WM_KEYDOWN)
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(在低16位指明show-window(SW_)(指明了操作). For a list of show-window values, see theShowWindow(想要了解show-window值的详细清单,参考theShowWindow). The high-order word is undefined.(高16位未定义)
HCBT_MOVESIZE Specifies the handle to the window to be moved or sized(指明将要被移动或者是改变大小的窗口句柄). Specifies a long pointer to aRECT structure containing the coordinates of the window(指明一个指向aRECT结构(包含了窗口的坐标)的long指针). By changing the values in the structure, a CBTProc hook procedure can set the final coordinates of the window.(通过更改这个结构的值,CBTProc钩子程序可以设置窗口的最终坐标)
HCBT_QS Is undefined and must be zero(未定义,必须被设置成0). Is undefined and must be zero.(未定义,必须被设置成0).
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.(指明一个系统命令值(SC_)(它指明了系统命令) For more information about system-command values, seeWM_SYSCOMMAND(想了解更多关于系统命令值的信息,参考WM_SYSCOMMAND). Contains the same data as the lParam value of aWM_SYSCOMMAND message(象aWM_SYSCOMMAND消息的lParam值一样,包含了相同的数据:): If a system menu command is chosen with the mouse, the low-order word contains the x-coordinate of the cursor, in screen coordinates, and the high-order word contains the y-coordinate; otherwise, the parameter is not used(如果用鼠标选择了一个系统菜单命令,低16位包含了鼠标在屏幕坐标系里的x坐标,高16位包含了y坐标;否则,这个参数不会被使用).
我也翻译的不好,你将就吧,以后有时间接着弄。
时间仓促,错误纰漏极多,望大家指正。
BTW:arhat是不是说我老不翻译完全啊?现在终于弄完啦