Y
yjq2003
Unregistered / Unconfirmed
GUEST, unregistred user!
如何才能截住其他应用程序的菜单的消息WM_COMMAND。我用全局钩子,怎么截不住?
代码如下:
#pragma data_seg("SharedDataName")
HHOOK hCallHook=NULL;
HINSTANCE hIns=NULL;
#pragma data_seg()
LRESULT CALLBACK CallProc(int nCode,WPARAM wParam,LPARAM lParam)
{
CWPSTRUCT *pStruct=(CWPSTRUCT*)lParam;
while (nCode==HC_ACTION)
{
if (pStruct->message==WM_COMMAND)
{
MessageBox(NULL,TEXT("WM_COMMAND"),NULL,0);
}
else
{
break;
}
}
return CallNextHookEx (hCallHook, nCode, wParam, lParam);
}
extern "C" BOOL WINAPI InstallCallHook()
{
if (hCallHook==NULL)
{
hCallHook=SetWindowsHookEx(WH_CALLWNDPROC,(HOOKPROC)CallProc,hIns,0);
if (hCallHook!=NULL) return TRUE;
}
else
return FALSE;
}
代码如下:
#pragma data_seg("SharedDataName")
HHOOK hCallHook=NULL;
HINSTANCE hIns=NULL;
#pragma data_seg()
LRESULT CALLBACK CallProc(int nCode,WPARAM wParam,LPARAM lParam)
{
CWPSTRUCT *pStruct=(CWPSTRUCT*)lParam;
while (nCode==HC_ACTION)
{
if (pStruct->message==WM_COMMAND)
{
MessageBox(NULL,TEXT("WM_COMMAND"),NULL,0);
}
else
{
break;
}
}
return CallNextHookEx (hCallHook, nCode, wParam, lParam);
}
extern "C" BOOL WINAPI InstallCallHook()
{
if (hCallHook==NULL)
{
hCallHook=SetWindowsHookEx(WH_CALLWNDPROC,(HOOKPROC)CallProc,hIns,0);
if (hCallHook!=NULL) return TRUE;
}
else
return FALSE;
}