首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

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

2012-01-20 
MFC中,想获取消息?请各位大哥帮帮忙在WIN32程序中:自己写的一个函数ProcessMessage(MSG*msg)while(GetMes

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()

热点排行