Chapter 12: Dialog-Based Windows Visual C++ and MFC Fundamentals
{
public:
enum { IDD = IDD_EXERCISE_DLG };
CExerciseDlg();
~CExerciseDlg();
};
CExerciseDlg::CExerciseDlg()
: CDialog(CExerciseDlg::IDD)
{
}
CExerciseDlg::~CExerciseDlg()
{
}
- Before using the new class, declare a variable of it as follows:
BOOL CExerciseApp::InitInstance()
{
CExerciseDlg Dlg;
m_pMainWnd = &Dlg;
return TRUE;
}
- Save All
12.2 Modal Dialog Boxes...................................................................................
12.2.1..Dialog-Based Applications................................................................
There are two types of dialog boxes: modal and modeless. A Modal dialog box is one that
the user must first close in order to have access to any other framed window or dialog
box of the same application.
One of the scenarios in which you use a dialog box is to create an application that is
centered around a dialog box. In this case, if either there is no other window in your
application or all the other windows depend on this central dialog box, it must be created
as modal. Such an application is referred to as dialog-based
There are two main techniques you can use to create a dialog-based application: from
scratch or using one of Visual C++ wizards. After creating a dialog resource and deriving
a class from CDialog, you can declare a variable of your dialog class. To display your
dialog box as modal, you can call the CDialog::DoModal() method in your
CWinApp::InitInstance() method. Its syntax is:
virtual int DoModal();
This method by itself does nothing more than displaying a dialog box as modal. We will
learn that you can use this method to find out how the user had closed such a dialog box.