参考以下帖子,
解决
http://topic.youkuaiyun.com/t/20030515/09/1785909.html
在WM_SHOWWINDOW中试试
void CTestdlg3Dlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
CEdit* pedit=(CEdit*)GetDlgItem(IDC_EDIT);
pedit-> SetFocus();
}
在InitDialog中要设置某个控件的焦点,必须返回FALSE
BOOL CODBCLiborDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//……
CButton* pButton = static_cast <CButton*> (GetDlgItem(IDC_BTN));
ASSERT(pButton != NULL);
pButton-> SetFocus();
return FALSE;
}
我用的第二种方法
因为在第二种方法,有如下提示:
BOOL CDialogLogin::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
本文介绍了在MFC中如何为对话框中的控件设置焦点。通过两种不同的方法实现:一是在WM_SHOWWINDOW消息处理函数中设置,二是通过OnInitDialog函数进行设置。需要注意的是,在OnInitDialog中设置控件焦点时,为了确保焦点设置成功,函数需返回FALSE。
3974

被折叠的 条评论
为什么被折叠?



