我建了一个单文档程序,在CMainFrame中的OnChar()中添加MessageBox("hello");执行程序,为什么不响应呢?我按下了键盘呀?

解决方案 »

  1.   

    在PreTranslateMessage中处理
    BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) 
    {
    // TODO: Add your specialized code here and/or call the base class if (WM_CHAR == pMsg->message)
                AfxMessageBox("hello"); return CFrameWnd::PreTranslateMessage(pMsg);
    }
    不过, WM_CHAR必须由WM_KEYDOWN经过TranslateMessage得到,如果你当前拥有焦点的控件无法进行输入,则收不到WM_CHAR消息
      

  2.   

    PreTranslateMessage和TranslateMessage是什么关系呀?
    如果这样处理的话,岂不是OnChar函数白白定义了吗?
      

  3.   

    OnChar只有在拥有焦点的控件才能响应,要定义的话也是在CView里
      

  4.   

    我觉得好好奇怪哦:
    1.我在CView中也加了OnChar,同时还有你说的上面的代码,这两个同时执行了,先执行的MainFrame中的,然后是CView中的OnChar(),为什么啊
    2. 我在CView中又加了一个KeyDown的函数,先执行View中的ONChar(),然后是view中的OnKeyDown(),CMainFrame中的就不执行了,
    太奇怪了?!