钩子(HOOK)函数教程(十四)

时间:2010年04月21日 点击:640

方法9  :JournalPlaybackProc Function

The JournalPlaybackProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. Typically, an application uses this function to play back a series of mouse and keyboard messages recorded previously by the JournalRecordProc hook procedure. As long as a JournalPlaybackProc hook procedure is installed, regular mouse and keyboard input is disabled.

JournalPlaybackProc钩子子程是和SetWindowsHookEx方法一起使用的、程序定义的或者库定义的回调函数。典型的,应用程序使用该方法回放前期由JournalRecordProc钩子子程记录下来的一系列鼠标和键盘消息。只要JournalPlaybackProc钩子子程被安装,常规的鼠标和键盘输入将被禁用。

The HOOKPROC type defines a pointer to this callback function. JournalPlaybackProc is a placeholder for the application-defined or library-defined function name. HOOKPROC类型定义了指向该回调函数的指针。JournalPlaybackProc 是程序定义的或者库定义的方法名字。

Syntax 语法

LRESULT CALLBACK JournalPlaybackProc(      
        int code,

    WPARAM wParam,

    LPARAM lParam

);

Parameters 参数

code [in] Specifies a code the hook procedure uses to determine how to process the message. If code 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.

指定钩子子程使用的代码,以决定如何处理该消息。如果参数code小于0,钩子子程不对其进行任何进一步的处理,必须将消息传递给CallNextHookEx方法,返回由CallNextHookEx方法返回的返回值。该参数可以是下列值之一:

1HC_GETNEXT The hook procedure must copy the current mouse or keyboard message to the EVENTMSG structure pointed to by the lParam parameter.

钩子子程必须将当前鼠标或者键盘消息拷贝给由参数lParam指向的EVENTMSG结构。

2HC_NOREMOVE An application has called the PeekMessage function with wRemoveMsg set to PM_NOREMOVE, indicating that the message is not removed from the message queue after PeekMessage processing. 应用程序已经调用带有指向PM_NOREMOVE wRemoveMsg 集合的PeekMessage方法,指示该消息在PeekMessage处理完毕后,没有从消息队列中移除。

3HC_SKIP  The hook procedure must prepare to copy the next mouse or keyboard message to the EVENTMSG structure pointed to by lParam. Upon receiving the HC_GETNEXT code, the hook procedure must copy the message to the structure. 钩子子程必须准备拷贝下一个鼠标或者键盘消息到由lParam 指向的 EVENTMSG结构。一旦接收到HC_GETNEXT代码,钩子子程必须将消息拷贝到结构体中。

4HC_SYSMODALOFF A system-modal dialog box has been destroyed. The hook procedure must resume playing back the messages. 系统模式的对话框已经被销毁。钩子子程应该恢复回放消息。

5HC_SYSMODALON   A system-modal dialog box is being displayed. Until the dialog box is destroyed, the hook procedure must stop playing back messages.系统模式的对话框正在被显示。钩子子程应该停止回放消息,直到对话框被销毁。

wParam This parameter is not used. 该参数未使用。

lParam  [in] Pointer to an EVENTMSG structure that represents a message being processed by the hook procedure. This parameter is valid only when the code parameter is HC_GETNEXT.  指向EVENTMSG结构的指针,该结构代表正在被钩子子程处理的消息。只有当参数codeHC_GETNEXT时该参数才有效。

Return Value返回值

To have the system wait before processing the message, the return value must be the amount of time, in clock ticks, that the system should wait. (This value can be computed by calculating the difference between the time members in the current and previous input messages.) To process the message immediately, the return value should be zero. The return value is used only if the hook code is HC_GETNEXT; otherwise, it is ignored.

为了使系统在处理消息之前等待,该返回值应该是系统应该等待的时间数量,该值以时钟嘀嗒为单位(该值可以通过当前和前一个输入消息的time成员的差值来计算)。为了快速的处理该消息,返回值应该是0。只有当钩子代码是HC_GETNEXT时,返回值才有意义;否则,该参数被忽略。

Remarks 备注

A JournalPlaybackProc hook procedure should copy an input message to the lParam parameter. The message must have been previously recorded by using a JournalRecordProc hook procedure, which should not modify the message.

JournalPlaybackProc钩子子程应该拷贝一个输入消息到lparm参数。消息必须在先前已经使用JournalRecordProc钩子子程被记录了下来,JournalRecordProc钩子子程不应修改消息。

To retrieve the same message over and over, the hook procedure can be called several times with the code parameter set to HC_GETNEXT without an intervening call with code set to HC_SKIP.

为了一遍又一遍的得到同样的消息,钩子子程在将code参数设置为HC_GETNEXT的情况下,可以被调用多次,而不涉及将code参数设置为HC_SKIP的调用。

If code is HC_GETNEXT and the return value is greater than zero, the system sleeps for the number of milliseconds specified by the return value. When the system continues, it calls the hook procedure again with code set to HC_GETNEXT to retrieve the same message. The return value from this new call to JournalPlaybackProc should be zero; otherwise, the system will go back to sleep for the number of milliseconds specified by the return value, call JournalPlaybackProc again, and so on. The system will appear to be not responding.

如果参数code HC_GETNEXT,而且返回值大于0,系统将休眠,休眠时间是返回值指定的毫秒数。当系统继续的时候,调用钩子子程,钩子子程通过将code设置为HC_GETNEXT来重新得到同一个的消息。从新的JournalPlaybackProc调用得到的返回值应该是0;否则,系统将回到休眠状态,休眠时间是返回值指定的毫秒数,休眠过后再次调用JournalPlaybackProc以此类推。系统看起来像没有响应一样。

Unlike most other global hook procedures, the JournalRecordProc and JournalPlaybackProc hook procedures are always called in the context of the thread that set the hook.

和其他全局的钩子子程不一样,JournalRecordProc JournalPlaybackProc钩子子程永远在设置该钩子的线程的上下文中被调用。

After the hook procedure returns control to the system, the message continues to be processed. If code is HC_SKIP, the hook procedure must prepare to return the next recorded event message on its next call.

在钩子子程将控制权交还给系统之后,消息被继续处理。如果code参数是HC_SKIP ,钩子子程必须准备在下一次调用时返回下一条记录的事件消息。

Install the JournalPlaybackProc hook procedure by specifying the WH_JOURNALPLAYBACK hook type and a pointer to the hook procedure in a call to the SetWindowsHookEx function.

通过指定WH_JOURNALPLAYBACK钩子类型,以及一个钩子子程的指针(该子程在SetWindowsHookEx方法中被调用)来安装JournalPlaybackProc钩子子程。

If the user presses CTRL+ESC OR CTRL+ALT+DEL during journal playback, the system stops the playback, unhooks the journal playback procedure, and posts a WM_CANCELJOURNAL message to the journaling application.

在回放过程中,如果用户按下了 CTRL+ESC 或者 CTRL+ALT+DEL组合键,系统将停止回放,卸载回放钩子子程,传递一个WM_CANCELJOURNAL消息给记录应用程序。

If the hook procedure returns a message in the range WM_KEYFIRST to WM_KEYLAST, the following conditions apply:

如果钩子子程返回一个在WM_KEYFIRSTWM_KEYLAST范围内的消息,下列条件应用:

The paramL member of the EVENTMSG structure specifies the virtual key code of the key that was pressed. EVENTMSG结构的paramL成员指定被按下键的虚拟键码。

The paramH member of the EVENTMSG structure specifies the scan code. EVENTMSG结构的paramL成员指定扫描码。

There's no way to specify a repeat count. The event is always taken to represent one key event. 没有办法指定重复的计数。事件总是趋于代表一个键事件。

                                Helios  2007-4-26

 

 

赞助商链接

热门内容

相关内容

联系我们

联系方式