鉤子教程 - 原理(十) : CBTProc

原文地址:http://www.zdexe.com/program/201004/584.htmlhtml

方法5  :  CBTProc Functionapp

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.less

CBTProc鉤子子程是和SetWindowsHookEx方法同時使用的、程序定義的或者庫定義的回調函數。系統在下列事件發生以前調用該方法:函數

  1.激活、建立、銷燬、最小化、最大化、移動窗體、改變窗體大小;this

  2.完成系統命令;spa

  3.從系統消息隊列中移除鼠標或者鍵盤事件;指針

  4.設置鍵盤焦點;code

  5.同步系統消息隊列。orm

CBT應用程序使用該鉤子子程接收來自系統的有用的通知。htm

 

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是程序定義的或者庫定義的方法名字。

 

LRESULT CALLBACK CBTProc(     

    int nCode,

    WPARAM wParam,

    LPARAM lParam

);

Parameters 參數

nCode  :[in] Specifies a code that the hook procedure uses to determine how to process the message. 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. This parameter can be one of the following values.

  指定一個碼值,鉤子子程使用該值來決定如何處理消息。若是nCode小於0,鉤子子程就必須將該消息傳遞給CallNextHookEx方法,本身不對消息作進一步的處理,而且應該返回由CallNextHookEx方法返回的返回值。該參數能夠是如下值中的一個:

1.HCBT_ACTIVATE  :The system is about to activate a window. 

  系統即將建立一個窗體。

 

2.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_JOURNALPLAYBAC鉤子子程來響應鼠標消息。

 

3.HCBT_CREATEWND : A window is about to be created. The system calls the hook procedure before sending the WM_CREATE or WM_NCCREATE message to the window. If the hook procedure returns a nonzero value, the system destroys the window; the CreateWindow function returns NULL, but the WM_DESTROY message is not sent to the window. If the hook procedure returns zero, the window is created normally. 

  窗體即將被建立。系統在向窗體發出WM_CREATE 或者 WM_NCCREATE消息以前,調用該鉤子子程。若是鉤子子程返回非0值,表示系統銷燬了窗體;CreateWindow方法返回Null,可是WM_DESTROY消息並不發送給窗體。若是鉤子子程返回0,表示窗體正常被建立。

 

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.

  在 HCBT_CREATEWND通知的時候,窗體已經被建立了,可是它的最終的大小和位置可能尚未被肯定,它的父窗體也可能沒有被建立起來。雖然一個新建立的窗體可能尚未接收到WM_NCCREATE或者WM_CREATE消息,可是向它發送消息是可能的。經過修改CBT_CREATEWND 結構體的hwndInsertAfter成員,改變新建立窗體的在Z軸次序的位置也是可能的。

 

4.HCBT_DESTROYWND :A window is about to be destroyed. 

  窗體即將被銷燬。

5.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 procedure in response to the keyboard message. 

  系統已經從系統的消息隊列中移除了一個鍵盤消息。一旦接收到該鉤子代碼,CBT應用程序必須安裝一個WH_JOURNALPLAYBAC鉤子來響應鍵盤消息。

6.HCBT_MINMAX :A window is about to be minimized or maximized.

  窗體即將被最小化或者最大化。

7.HCBT_MOVESIZE :A window is about to be moved or sized. 

  窗體即將被移動或者重置大小。

8.HCBT_QS  :The system has retrieved a WM_QUEUESYNC message from the system message queue. 

  系統已經收到了一個來自系統消息隊列的WM_QUEUESYNC消息。

9.HCBT_SETFOCUS  :A window is about to receive the keyboard focus.

  窗體即將接收鍵盤焦點。

10.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程序阻止經過快捷鍵來進行任務切換。

 

wParam :[in] Depends on the nCode parameter. 

 

  取決於參數 nCode

lParam :[in] Depends on the nCode parameter. 

  取決於參數 nCode

 

Return Value 返回值

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

相關文章
相關標籤/搜索