原文地址:http://www.zdexe.com/program/201004/587.htmlhtml
方法8 : GetMsgProc Functionapp
The GetMsgProc function is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function whenever the GetMessage or PeekMessage function has retrieved a message from an application message queue. Before returning the retrieved message to the caller, the system passes the message to the hook procedure.less
GetMsgProc是和SetWindowsHookEx方法一塊兒使用的、程序定義的或者庫定義的回調函數。不管何時,當GetMessage 或者 PeekMessage方法接收到來自應用程序消息隊列的消息時,系統都會調用該方法。在將收到的消息返回給調用者以前,系統將消息傳遞給鉤子子程。函數
The HOOKPROC type defines a pointer to this callback function.GetMsgProc is a placeholder for the application-defined or library-defined function name. this
HOOKPROC類型定義了指向該回調函數的指針。GetMsgProc是程序定義的或者庫定義的方法名字。spa
Syntax 語法指針
LRESULT CALLBACK GetMsgProc(
int code,code
WPARAM wParam,htm
LPARAM lParam隊列
);
Parameters 參數
code : [in] Specifies whether the hook procedure must process the message. If code is HC_ACTION, the hook procedure must 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.
指定鉤子子程是否必須處理消息。若是nCode是HC_ACTION,鉤子子程就必須處理該消息。若是nCode小於0,鉤子子程就必須將該消息傳遞給CallNextHookEx方法,本身對消息不作進一步處理,而且應該返回由CallNextHookEx方法返回的返回值。
wParam :[in] Specifies whether the message has been removed from the queue. This parameter can be one of the following values.
指定消息是否已經被從隊列中移除了。該參數能夠是下列值中的一個:
1.PM_NOREMOVE :Specifies that the message has not been removed from the queue. (An application called the function, specifying the PM_NOREMOVE flag.)
指定消息還沒有從隊列中移出。(應用程序在調用該方法的同時指定PM_NOREMOVE標誌)
2.PM_REMOVE Specifies that the message has been removed from the queue. (An application called GetMessage, or it called the PeekMessagefunction, specifying the PM_REMOVE flag.)
指定消息已經被從隊列中移除了。(程序調用GetMessage 或者PeekMessage方法的同時指定PM_REMOVE標誌)
lParam :[in] Pointer to an MSG structure that contains details about the message.
指向MSG結構的指針,結構中包含和消息相關的細節。
Return Value 返回值
If code is less than zero, the hook procedure must return the value returned by CallNextHookEx. If code is greater than or equal to zero, it is highly recommended that you call CallNextHookEx and return the value it returns; otherwise, other applications that have installed WH_GETMESSAGE hooks will not receive hook notifications and may behave incorrectly as a result. If the hook procedure does not call CallNextHookEx, the return value should be zero.
若是參數code小於0,鉤子子程必須返回由CallNextHookEx返回的返回值。
若是參數code大於等於0,強烈要求調用CallNextHookEx方法,並返回由該方法返回的返回值;不然,其餘已經安裝了WH_GETMESSAGE鉤子的程序將收不到鉤子通知,可能致使行爲的錯誤。若是鉤子子程沒有調用CallNextHookEx方法,返回值應該是0
Remarks 備註
The GetMsgProc hook procedure can examine or modify the message. After the hook procedure returns control to the system, the GetMessage orPeekMessage function returns the message, along with any modifications, to the application that originally called it.
GetMsgProc鉤子子程可以檢查或者修改消息。在鉤子子程將控制權交還給系統以後,GetMessage 或者PeekMessage方法將該消息以及任何修改都一塊兒返回給最初調用它的應用程序。
An application installs this hook procedure by specifying theWH_GETMESSAGE hook type and a pointer to the hook procedure in a call to the SetWindowsHookEx function.
應用程序經過下面方式安裝該鉤子子程:指定WH_ GETMESSAGE鉤子類型;指定在調用SetWindowsHookEx方法的函數中指向鉤子子程的指針。