Udostępnij za pośrednictwem


CDialog::EndDialog

Call this member function to terminate a modal dialog box.

void EndDialog(
   int nResult 
);

Parameters

  • nResult
    Contains the value to be returned from the dialog box to the caller of DoModal.

Remarks

This member function returns nResult as the return value of DoModal. You must use the EndDialog function to complete processing whenever a modal dialog box is created.

You can call EndDialog at any time, even in OnInitDialog, in which case you should close the dialog box before it is shown or before the input focus is set.

EndDialog does not close the dialog box immediately. Instead, it sets a flag that directs the dialog box to close as soon as the current message handler returns.

Example

void CMyDialog::OnMenuShowSimpleModal()
{
   CSimpleDlg myDlg;
   INT_PTR nRet = myDlg.DoModal();

   if (nRet == IDOK || nRet == 5)
      AfxMessageBox(_T("Dialog closed successfully"));
}
void CSimpleDlg::OnRButtonUp(UINT nFlags, CPoint point)
{
   UNREFERENCED_PARAMETER(nFlags);
   // Do something

   int nRet = point.x; // Just any value would do!
   EndDialog(nRet); // This value is returned by DoModal!

   // Do something

   return; // Dialog closed and DoModal returns only here!
}

Requirements

Header: afxwin.h

See Also

Reference

CDialog Class

Hierarchy Chart

CDialog::DoModal

CDialog::OnOK

CDialog::OnCancel

Other Resources

CDialog Members