希望回车时该按钮被按下。谢谢!
高手们的回答,怎么都不行啊?

解决方案 »

  1.   

    BOOL CMyDialog::PreTranslateMessage(MSG *pMsg)
    {
       if (pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
       {
           GetDlgItem(IDC_BUTTON)->SetFocus();
           if( GetFocus == (CWnd*)GetDlgItem(IDC_BUTTON))
           {
                 OnButton();
                 return TRUE;
            } 
         
        }
        // be a good citizen - call the base class
        return CDialog::PreTranslateMessage(pMsg);
    }再试试^_^!!
      

  2.   

    现在行了。只是窗口初始化的时候焦点还不在按钮上边,回车的时候才过去。CButton类的成员函数SetCheck(TRUE)应该也可以吧,就是不知道如何获得
    CButton类型的指针才能调用这个函数。
      

  3.   

    为什么在OnInitDialog()中SetFocus()无效?????
      

  4.   

    在WM_ShowWindow中试试
    void CTestdlg3Dlg::OnShowWindow(BOOL bShow, UINT nStatus) 
    {
    CDialog::OnShowWindow(bShow, nStatus);

    // TODO: Add your message handler code here
    CButton* pt=(CButton*)GetDlgItem(IDC_BUTTON1);
    pt->SetFocus();
    }
      

  5.   

    在OnInitDialog中设置后要返回FALSE, VC生成的代码中有注释的
      

  6.   

    将你的按钮属性中的Default button打勾,初始华窗口后那个按钮就会获得焦点,应该是你想要的吧