What I wish to do is, after creating a dialog box with DoModal()
and pressing OK in the box to exit it, to have a custom value returned. For example, a couple o
I was looking for an answer and agree that in most cases that you would not change the standard behavior of a dialog. But there might be a case where you would like to pick what the user is actually responding say if you had several buttons and want specifically that they picked the OK at the top versus the OK at the bottom. You know for metrics.
Or say if you wanted to have slightly different results if the dialog caused an error when running on of your functions. It would be nice to return a value that is not IDOK but maybe some other value.
I found Dialog::EndDialog()
with details and an example of usage here: MSDN: Dialog::EndDialog
#include "ANewDialog.h"
void CMyWnd::ShowDialog()
{
CMyDialog myDlg;
int nRet = myDlg.DoModal();
if ( nRet == 18 )
AfxMessageBox("Dialog closed. But there was a problem.");
}
/* MyDialog.cpp */
void CMyDialog::OnSomeButtonAction()
{
int nRet = 0;
// Run your function with return value;
nRet = YourReallyFunFunction();
EndDialog(nRet); // Set the return value returned by DoModal!
return; // The dialog closes and DoModal returns here!
}