解决方案 »

  1.   

    这里主要是一个焦点的问题!
    所谓”对话框中的按ENTER键的消息“实际上接收该消息的都是对话框的子控件。
    所以你需要重载子控件,并进行按键消息的处理。
    ENTER键为VK_RETURN
      

  2.   

    对话框相应enter键的函数是onok()把CDialog::OnOk();屏蔽掉就可以干你要干的事情
      

  3.   

    你可以加一个按钮然后将他默认属性(default)选中然后在他的Click消息里写程序也可以
      

  4.   

    BOOL CYourDlg::PreTranslateMessage(MSG* pMsg) 
    {
    // TODO: Add your specialized code here and/or call the base class
    if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
    return 1;

    return CDialog::PreTranslateMessage(pMsg);
    }
      

  5.   

    在 对 话 框 的 PreTranslateMessage(MSG* pMsg) 消 息 响 应 函 数 中 加 入 下 列 代 码 : 
    if (pMsg->wParam == 0x0D ) { // ENTER键 

    DoEnter();
    return 0;

    if (pMsg->wParam == 0x1B) { // Cancel键 

    DoCancel();
    return 0;
    }
      

  6.   

    重载函数:PreTranslateMessage
    BOOL <ClassName>::PreTranslateMessage(MSG* pMsg) 
    {
    if (pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
    {
    // handle KEY_ENTER
    DWORD def_id=GetDefID();
    if (def_id!=0)
    {
    CWnd *wnd=FromHandle(pMsg->hwnd);
    // you may implement other ways of testing, e.g.
    //  comparing to array of CWnd*, comparing to array of IDs etc.         //或许你只想处理基于某一控件的回车键
    char class_name[16];
    if (GetClassName(wnd->GetSafeHwnd(),class_name,sizeof(class_name))!=0)
    {
    if (strnicmp(class_name,"edit",5)==0)
    {
    //忽略或转译成TAB键
                               pMsg->wParam = VK_TAB;
    }
    }
       }
    } return CDialog::PreTranslateMessage(pMsg);
    }
      

  7.   

    BOOL CMEDesktopDlg::PreTranslateMessage(MSG* pMsg) 
    {
    // TODO: Add your specialized code here and/or call the base class
    if(pMsg->message == WM_KEYDOWN)
    {
    if(pMsg->wParam == VK_RETURN)
                       {
                               // do your code here
                               ...
    return TRUE;
                       }
    else if(pMsg->wParam == VK_ESCAPE)
    return TRUE;
    }
    return CDialog::PreTranslateMessage(pMsg);
    }
      

  8.   

    PreTranslateMessage里面判断按键是否为回车,然后做相应的处理