在WIN32程序中:自己写的一个函数ProcessMessage(MSG*msg);while (GetMessage(&msgMsg, NULL, 0, 0))
{
if (ProcessMessage(&msgMsg) == FALSE)
{
TranslateMessage(&msgMsg);
DispatchMessage(&msgMsg);
}
}请问在MFC 对话框 中怎么实现相同功能,也就是能够所有消息都先通过ProcessMessage()的检查,然后解析并分发消息。我重载了PreTranslateMessage(),好象不行,得不到我想要的消息。

解决方案 »

  1.   

    用钩子,google 一下吧 vc hook 钩子
      

  2.   

    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);   
      }
      

  3.   

    MFC不需要这么写啊。直接写消息处理函数就可以了。
    在CPP文件里面定义消息,在.H文件里面定义消息处理函数就好了
    ON_MESSAGE()