各位大侠,我从CWnd派生了一个类CDebugEdit,并重载了它的OnChar函数
然后将它创建在了一个Dialog上,在OnInitDialog函数里面加入了m_debugedit.Create(NULL, NULL, WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_VSCROLL|WS_BORDER,CRect(50, 50, 300, 200), this, 110, NULL);
但运行时,CDebugEdit都不响应WM_CHAR消息,请各位大侠救命!!

解决方案 »

  1.   

    是不是你的CDebugEdit没有获得焦点呀。
    The WM_CHAR message is posted to the window with the keyboard focus when a WM_KEYDOWN message is translated by the TranslateMessage function.
      

  2.   

    好象只有CEdit 和CRichEditCtrl能够响应WM_CHAR消息
      

  3.   

    要用SetFours设置你的窗口,使它有输入焦点。
      

  4.   

    to 高手:
    已经获得焦点了,也可以响应WM_KEYDOWN消息!
    在PreTranslateMessage里面也可以截获WM_CHAR消息
    if((pMsg->message == WM_CHAR)&&(pMsg->hwnd == m_hWnd))
    {
      return CWnd::PreTranslateMessage(pMsg);
    }
    但跟进CWnd::PreTranslateMessage(pMsg)函数时发现:
    BOOL CWnd::PreTranslateMessage(MSG* pMsg)
    {
    // handle tooltip messages (some messages cancel, some may cause it to popup)
    AFX_MODULE_STATE* pModuleState = _AFX_CMDTARGET_GETSTATE();
    if (pModuleState->m_pfnFilterToolTipMessage != NULL)
       (*pModuleState->m_pfnFilterToolTipMessage)(pMsg, this);// no default processing
    return FALSE;
    }跟踪发现pModuleState->m_pfnFilterToolTipMessage == NULL
    函数CWnd::PreTranslateMessage(MSG* pMsg)的返回为FALSE!
      

  5.   

    各位大侠,另外我还发现一个奇怪的现象,就是:
    如果加入如下代码
    void CDebugEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
    {
    // TODO: Add your message handler code here and/or call default CString Msg;
    Msg.Format("%c", nChar);
    AfxMessageBox(Msg);
    CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
    }void CDebugEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
    {
    // TODO: Add your message handler code here and/or call default
    CString Msg;
    Msg.Format("%c", nChar);
    AfxMessageBox(Msg);
    CWnd::OnChar(nChar, nRepCnt, nFlags);
    }则按键时会有响应,弹出两个消息框,但我如果将OnKeyDown中的“AfxMessageBox(Msg);”注释掉,则WM_CHAR没有响应,注释OnKeyDown中的其它代码时,WM_CHAR也可以响应。
    晕晕晕!!!急急急!!!
      

  6.   

    用SPY++观察一下消息流。看看有什么问题没有
      

  7.   

    papaya_stone(^_^)shentong(^_^) :
    CWnd::WindowProc是什么意思?是要查哪方面?请多提示一点,谢谢!to tigerfox(混合体:=初级程序员 . 正在郁闷中):
    SPY++观察没有什么异常
      

  8.   

    哈哈,这是个子类化的问题,在MSDN里找找关于SUBCLASSWINDOWS的内容
      

  9.   

    WM_CHAR消息好像就是不发送到对话框的控件窗口中去的。解决办法是:在PreTranslateMessage中截获WM_CHAR消息,直接调用OnChar函数,OnChar函数所需的参数在pMsg中全有。
    OnChar( pMsg->wParam,lParam & 0xffff,lParam);
      

  10.   

    补充一点:
     这时不能在调用CWnd::PreTranslateMessage(pMsg),而是直接返回TRUE
      

  11.   

    to zhuxl0609(zxl):
    果然是高手,太谢谢你了!