原文地址:http://www.zdexe.com/program/201004/588.htmlhtml
方法9 :JournalPlaybackProc Functionapp
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.less
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. post
HOOKPROC類型定義了指向該回調函數的指針。JournalPlaybackProc 是程序定義的或者庫定義的方法名字。this
Syntax 語法spa
LRESULT CALLBACK JournalPlaybackProc(
int code,線程
WPARAM wParam,指針
LPARAM lParamcode
);
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方法返回的返回值。該參數能夠是下列值之一:
1.HC_GETNEXT :The hook procedure must copy the current mouse or keyboard message to the EVENTMSG structure pointed to by the lParamparameter.
鉤子子程必須將當前鼠標或者鍵盤消息拷貝給由參數lParam指向的EVENTMSG結構。
2.HC_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 PeekMessageprocessing.
應用程序已經調用帶有指向PM_NOREMOVE的 wRemoveMsg 集合的PeekMessage方法,指示該消息在PeekMessage處理完畢後,沒有從消息隊列中移除。
3.HC_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代碼,鉤子子程必須將消息拷貝到結構體中。
4.HC_SYSMODALOFF : A system-modal dialog box has been destroyed. The hook procedure must resume playing back the messages.
系統模式的對話框已經被銷燬。鉤子子程應該恢復回放消息。
5.HC_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結構的指針,該結構表明正在被鉤子子程處理的消息。只有當參數code是HC_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 timemembers 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 andJournalPlaybackProc 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_KEYFIRST到WM_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.
沒有辦法指定重複的計數。事件老是趨於表明一個鍵事件。