读书人

MFC中想获取消息?请帮帮忙

发布时间: 2012-01-20 18:53:53 作者: rapoo

MFC中,想获取消息?请各位大哥帮帮忙
在WIN32程序中:

自己写的一个函数ProcessMessage(MSG*msg);

while (GetMessage(&msgMsg, NULL, 0, 0))
{
if (ProcessMessage(&msgMsg) == FALSE)
{
TranslateMessage(&msgMsg);
DispatchMessage(&msgMsg);
}
}

请问在MFC 对话框 中怎么实现相同功能,也就是能够所有消息都先通过ProcessMessage()的检查,然后解析并分发消息。我重载了PreTranslateMessage(),好象不行,得不到我想要的消息。

[解决办法]
用钩子,google 一下吧 vc hook 钩子
[解决办法]
PreTranslateMessage()是可以的:

BOOL CTestDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg-> message == WM_KEYDOWN){
if (pMsg-> wParam == VK_A)
AfxMessageBox( "a ");
}
return CDialog::PreTranslateMessage(pMsg);
}
[解决办法]
MFC不需要这么写啊。直接写消息处理函数就可以了。
在CPP文件里面定义消息,在.H文件里面定义消息处理函数就好了
ON_MESSAGE()

读书人网 >VC/MFC

热点推荐