CDialog::DoModal

CDialog::DoModal
  
说明:
  调用该成员函数使用模态对话框并返回对话框结果。当对话框处于活动状态时,该函数处理与用户的交互。这使得对话框是模态的,使用户在关闭对话框之前不能与其它窗口交互。

原型:
virtual int DoModal();
  
返回值:
  整数值,指定了传递给CDialog::EndDialog 的nResult参数值。该函数用于关闭对话框。如果函数不能创建对话框,则返回-1;如果出现其它错误,则返回IDABORT。
  
备注:  
如果用户单击了对话框中的按钮,如OK或Cancel,那么消息处理函数如OnOK或OnCancel被调用,从而关闭对话框。缺省的OnOK成员函数会对对话框数据进行有效性检验和更新,并关闭它得到结果IDOK。缺省OnCancel函数关闭对话框得到结果IDCANCEL,而不对对话框数据检验或更新,可以覆盖这些消息函数并改变它们的行为。注意 目前PreTransMessage被调用来处理模态对话框的消息。

例子:
void CTstApp::OnAppAbout()
{
   // Construct the dialog box passing the 
   // ID of the dialog template resource
   CDialog aboutDlg(IDD_ABOUTBOX);

   // Create and show the dialog box
   int nRet = -1;
   nRet = aboutDlg.DoModal();

   // Handle the return value from DoModal
   switch ( nRet )
   {
   case -1: 
      AfxMessageBox("Dialog box could not be created!");
      break;
   case IDABORT:
      // Do something
      break;
   case IDOK:
      // Do something
      break;
   case IDCANCEL:
      // Do something
      break;
   default:
      // Do something
      break;
   };
}


posted @ 2012-09-25 20:53  完美视界  阅读(1160)  评论(0编辑  收藏  举报