看MFC源码找不到CWnd::PreTranslateMessage是什么时候被调用的,没什么道理啊,CWinThread中的消息循环:
if(!PreTranslateMessage(...))
{
   ::TranslateMessage(..);
   ::DispatchMessage(..);
}
上面已经把msg消息翻译过了,那CWnd::PreTranslateMessage还有什么用呢?
统一窗口过程入口AfxWndProc中也没有PreTranslateMessage也没有啊。
哪位大哥能告诉我CWnd::PreTranslateMessage是什么时候被调用的吗?

解决方案 »

  1.   

    这是一个虚函数,vc6可以这样添加。比如你有一个多文档工程,右键点类名CChildFrame,选Add Virtual Function,在New Virtual Function里面选PreTranslateMessage,双击,OK。vc6就帮你添加了这个虚函数。当然你也可以手动添加。
    添加之后,
    BOOL CChildFrame::PreTranslateMessage(MSG* pMsg) 
    {
    // TODO: Add your specialized code here and/or call the base class

    return CMDIChildWnd::PreTranslateMessage(pMsg);
    }
    所有从CChildFrame过的消息都会进入这个函数。可以在里面处理,这个函数权限很大。要慎用
      

  2.   

    CWnd::PreTranslateMessage是什么时候被调用的在自己的类里面实现这个虚函数,然后下断点。看看什么时候被调用的吧
      

  3.   

    在你需要截取消息的时候加这个消息BOOL 类::PreTranslateMessage(MSG* pMsg) 
    {   
    if(pMsg->message == 什么消息) 
    {
                 //处理
    }

    return CDialog::PreTranslateMessage(pMsg);
    }
      

  4.   

    知道了,就是在CWinThread::PumpMessage()中的PreTranslateMessage()中走访了目的窗口过程的PreTranslateMessage(..),谢谢大家