在InitDialog中设置焦点不起作用 SETFOCUS

来源:互联网 发布:知无涯者 百度云 编辑:程序博客网 时间:2024/04/30 22:22

参考以下帖子,

解决

 

http://topic.csdn.net/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
}

原创粉丝点击