LRESULT __declspec(dllexport) CALLBACK CallWndProc(
int code,// hook code
WPARAM wParam,// undefined
LPARAM lParam // address of structure with message data (CWPSTRUCT)
)
{
LPCWPSTRUCT pCwpStruct = LPCWPSTRUCT(lParam);
if (HC_ACTION == code)
{
HWND hWnd = pCwpStruct->hwnd ;
UINT nMsg = pCwpStruct->message ;
WPARAM wp = pCwpStruct->wParam ;
int nID = LOWORD ( wp ) ;
if ( nMsg == WM_COMMAND && nID == IDOK )
{
MessageBox ( hWnd , "kokokok" , "HOOK" , MB_OK ) ;
return 0 ;
}
}
return CallNextHookEx(g_hCallWndProc,code,wParam,lParam);
}
试一试!
return 0; 好像会继续把消息传下去!
MSDN:
Return Values
If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx. If nCode 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_CALLWNDPROC 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.
If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx. If nCode 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. Res
The GetMsgProc hook procedure can examine or modify the message. After the hook procedure returns control to the system, theGetMessage function returns the message, along with any modifications, to the application that originally called it. 可以通过将消息值设为WM_NULL来吃掉消息,不是靠返回值