怎样在Edit控件中捕获到回车字符?
   我是这样做的:
     在对话框中的WM_CHAR或WM_KEYDOWN处理消息中写入代码:
       if(nChar==13)
          MessageBox("Hello");
    结果执行不成功.
    代码应该在哪写,怎么写?

解决方案 »

  1.   

    BOOL CAboutDlg::PreTranslateMessage(MSG* pMsg) 
    {
    if(pMsg->message == WM_KEYDOWN)
    {
    if(pMsg->wParam == 13 )
    {
    MessageBox("OK");
    return CDialog::PreTranslateMessage(pMsg);
    }
    }

    return CDialog::PreTranslateMessage(pMsg);
    }
      

  2.   

    可以自己扩展一下CEdit也可以如楼上所说,但是 楼上的法子似乎有些许不足
    因为当你不是在Cedit控件的时候 它也会响应
      

  3.   

    BOOL CAboutDlg::PreTranslateMessage(MSG* pMsg) 
    {
    if(pMsg->message == WM_KEYDOWN)
    {
                 CWnd * p = GetDlgItem(ID_EDIT);
    if(pMsg->wParam == 13 && pMsg->hwnd == p->m_hWnd)
    {
    MessageBox("OK");
    }
    }

    return CDialog::PreTranslateMessage(pMsg);
    }
      

  4.   

    1)屏蔽dialog的回车,ESC
    重载PreTranslateMessage()
    使用GetFocus()得到焦点
    对于相应的控件执行相应的操作,否则返回TRUEif( GetFocus()->GetDlgCtrlID() == IDC_EDIT1 )
    {
         if( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )
         {
               ...
         }
         else if
               ...
         else
               return TRUE;
         return CDialog::Pre...
    }
    2)移动焦点控件
    NextDlgCtrl()
    3)在文本框中输入字符,例如回车执行某一个事件,比如打开这个文本框中的字符对应的文件等。