CDialog::EndDialog
voidEndDialog(intnResult**);**
Parameters
nResult
Contains the value to be returned from the dialog box to the caller of DoModal.
Remarks
Call this member function to terminate a modal dialog box. 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
// MyWnd.cpp
#include "MyDialog.h"
void CMyWnd::ShowDialog()
{
CMyDialog myDlg;
int nRet = myDlg.DoModal();
if ( nRet == IDOK || nRet == 5 )
AfxMessageBox("Dialog closed successfully");
}
// MyDialog.cpp
void CMyDialog::OnSomeAction()
{
// Do something
int nRet = 5; // Just any value would do!
EndDialog(nRet); // This value is returned by DoModal!
// Do something
return; // Dialog closed and DoModal returns only here!
}
CDialog Overview | Class Members | Hierarchy Chart
See Also CDialog::DoModal, CDialog::OnOK, CDialog::OnCancel