Partilhar via


CDialog::DoModal

Call this member function to invoke the modal dialog box and return the dialog-box result when done.

virtual INT_PTR DoModal( );

Return Value

An int value that specifies the value of the nResult parameter that was passed to the CDialog::EndDialog member function, which is used to close the dialog box. The return value is –1 if the function could not create the dialog box, or IDABORT if some other error occurred, in which case the Output window will contain error information from GetLastError.

Remarks

This member function handles all interaction with the user while the dialog box is active. This is what makes the dialog box modal; that is, the user cannot interact with other windows until the dialog box is closed.

If the user clicks one of the pushbuttons in the dialog box, such as OK or Cancel, a message-handler member function, such as OnOK or OnCancel, is called to attempt to close the dialog box. The default OnOK member function will validate and update the dialog-box data and close the dialog box with result IDOK, and the default OnCancel member function will close the dialog box with result IDCANCEL without validating or updating the dialog-box data. You can override these message-handler functions to alter their behavior.

Observação

PreTranslateMessage is now called for modal dialog box message processing.

Example

void CMyDialog::OnMenuShowAboutDialog()
{
   // Construct the dialog box passing the 
   // ID of the dialog template resource
   CDialog aboutDlg(IDD_ABOUTBOX);

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

   // Handle the return value from DoModal
   switch (nRet)
   {
      case -1: 
         AfxMessageBox(_T("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;
   };
}

Requirements

Header: afxwin.h

See Also

Reference

CDialog Class

Hierarchy Chart

DialogBox

CWnd::IsDialogMessage

Other Resources

CDialog Members