如何拦截其他程序的菜单点击消息

N_G_U 2010-04-01 10:11:15
我主要想获得该程序菜单的wParam的值
我做了个WH_CALLWNDPROC钩子来勾WM_COMMAND,不过勾不到
不知道怎么回事.
...全文
187 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Swkjd 2010-04-02
  • 打赏
  • 举报
回复
试试这两个呢?

WH_MSGFILTER
Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. For more information, see the MessageProc hook procedure.

WH_SYSMSGFILTER
Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. The hook procedure monitors these messages for all applications in the same desktop as the calling thread. For more information, see the SysMsgProc hook procedure.

这是MSDN的解释,我也没用过。。
superhard_d 2010-04-02
  • 打赏
  • 举报
回复
挂窗口消息应该用SetWinEventHook
社会栋梁 2010-04-02
  • 打赏
  • 举报
回复
楼主show一下代码
N_G_U 2010-04-02
  • 打赏
  • 举报
回复
但是可以勾到WM_KEYUP的消息
N_G_U 2010-04-02
  • 打赏
  • 举报
回复
试了三种的钩子都不行:
WH_GETMESSAGE,WH_CALLWNDPROC,WH_CALLWNDPROCRET
N_G_U 2010-04-02
  • 打赏
  • 举报
回复
大概的代码如下:
#pragma data_seg("Shared")
TARGET_TYPE gMsgHookTarget = 0;
HINSTANCE ghInstance = NULL;
HHOOK ghMsgHook = NULL;
#pragma data_seg()
#pragma comment(linker,"/section:Shared,rws")



BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
if(ul_reason_for_call == DLL_PROCESS_ATTACH)
{
ghInstance = (HINSTANCE)hModule;
}
return TRUE;
}

LRESULT /*WINAPI*/ CALLBACK MsgHookProc(int nCode,WPARAM wparam,LPARAM lparam)
{
if(nCode == HC_ACTION)
{
TRACE(TEXT("+ "));
//PCWPSTRUCT pcs = NULL;
//pcs = (PCWPSTRUCT)lparam;
PMSG pcs = (PMSG)lparam;
if(pcs && pcs->hwnd != NULL)
{
TRACE(TEXT("0 "));
if(pcs->message == WM_COMMAND)
{
TRACE(TEXT("1 "));
}
}
}
return CallNextHookEx(ghMsgHook,nCode,wparam,lparam);
}

BOOL __stdcall StartMsgHook()
{
if(ghMsgHook != NULL)
return TRUE;

ghMsgHook = SetWindowsHookEx(WH_GETMESSAGE,MsgHookProc,ghInstance,0);

if(ghMsgHook)
{
return TRUE;
}

return FALSE;
}

BOOL __stdcall StopMsgHook()
{
if(ghMsgHook)
{
if(UnhookWindowsHookEx(ghMsgHook))
{
ghMsgHook = NULL;
return TRUE;
}
return FALSE;
}
return TRUE;
}

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧