波哥写的钩子教程4

来源:互联网 发布:京东天猫淘宝哪个好 编辑:程序博客网 时间:2024/06/06 05:38


钩子技术(六)
来源: 任立波的日志
方法5  :  CBTProcFunction

The CBTProc hook procedure is an application-defined orlibrary-defined callback function used with the SetWindowsHookExfunction. The system calls this function before activating,creating, destroying, minimizing, maximizing, moving, or sizing awindow; before completing a system command; before removing a mouseor keyboard event from the system message queue; before setting thekeyboard focus; or before synchronizing with the system messagequeue. A computer-based training (CBT) application uses this hookprocedure to receive useful notifications from the system.

CBTProc钩子子程是和SetWindowsHookEx方法同时使用的、程序定义的或者库定义的回调函数。系统在下列事件发生之前调用该方法:

<!--[if !supportLists]-->1. <!--[endif]-->激活、创建、销毁、最小化、最大化、移动窗体、改变窗体大小;

<!--[if !supportLists]-->2. <!--[endif]-->完成系统命令;

<!--[if !supportLists]-->3. <!--[endif]-->从系统消息队列中移除鼠标或者键盘事件;

<!--[if !supportLists]-->4. <!--[endif]-->设置键盘焦点;

<!--[if !supportLists]-->5. <!--[endif]-->同步系统消息队列。

CBT应用程序使用该钩子子程接收来自系统的有用的通知。

The HOOKPROC type defines a pointer to this callback function.CBTProc is a placeholder for the application-defined orlibrary-defined function name.

HOOKPROC类型定义了指向该回调函数的指针。CBTProc是程序定义的或者库定义的方法名字。

Syntax

LRESULT CALLBACK CBTProc(    

    intnCode,

    WPARAMwParam,

    LPARAMlParam

);

Parameters 参数

nCode  :[in] Specifies a code that the hookprocedure uses to determine how to process the message. If nCode isless than zero, the hook procedure must pass the message to theCallNextHookEx function without further processing and shouldreturn the value returned by CallNextHookEx. This parameter can beone of the following values.

指定一个码值,钩子子程使用该值来决定如何处理消息。如果nCode小于0,钩子子程就必须将该消息传递给CallNextHookEx方法,自己不对消息做进一步的处理,并且应该返回由CallNextHookEx方法返回的返回值。该参数可以是以下值中的一个:

1.HCBT_ACTIVATE  :The system is about toactivate a window. 系统即将创建一个窗体。

2.HCBT_CLICKSKIPPED  :The system has removeda mouse message from the system message queue. Upon receiving thishook code, a CBT application must install a WH_JOURNALPLAYBACK hookprocedure in response to the mouse message.系统已经将一个鼠标消息从系统消息队列中移除。一旦收到该钩子代码,CBT应用程序必须安装一个WH_JOURNALPLAYBAC钩子子程来响应鼠标消息。

3.HCBT_CREATEWND : A window is about to be created. The systemcalls the hook procedure before sending the WM_CREATE orWM_NCCREATE message to the window. If the hook procedure returns anonzero value, the system destroys the window; the CreateWindowfunction returns NULL, but the WM_DESTROY message is not sent tothe window. If the hook procedure returns zero, the window iscreated normally. 窗体即将被创建。系统在向窗体发出WM_CREATE 或者WM_NCCREATE消息之前,调用该钩子子程。如果钩子子程返回非0值,表示系统销毁了窗体;CreateWindow方法返回Null,但是WM_DESTROY消息并不发送给窗体。如果钩子子程返回0,表示窗体正常被创建。

At the time of the HCBT_CREATEWND notification, the window hasbeen created, but its final size and position may not have beendetermined and its parent window may not have been established. Itis possible to send messages to the newly created window, althoughit has not yet received WM_NCCREATE or WM_CREATE messages. It isalso possible to change the position in the z-order of the newlycreated window by modifying the hwndInsertAfter member of theCBT_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 messagefrom the system message queue. Upon receiving this hook code, a CBTapplication must install a WH_JOURNALPLAYBACK hook procedure inresponse 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 aWM_QUEUESYNC message from the system message queue.系统已经收到了一个来自系统消息队列的WM_QUEUESYNC消息。

9.HCBT_SETFOCUS  :A window is about toreceive the keyboard focus. 窗体即将接收键盘焦点。

10.HCBT_SYSCOMMAND :A system command is about to be carriedout. This allows a CBT application to prevent task switching bymeans 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 whetherthe system allows or prevents one of these operations. Foroperations corresponding to the following CBT hook codes, thereturn value must be 0 to allow the operation, or 1 to preventit:

钩子子程的返回值取决于系统允许还是阻止这种操作。对于下列这些操作的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
0 0
原创粉丝点击