Visual C++ and MFC Fundamentals Chapter 12: Dialog-Based Windows
BOOL InitInstance();
};
class CExerciseDlg : public CDialog
{
public:
enum { IDD = IDD_EXERCISE_DLG };
};
BOOL CExerciseApp::InitInstance()
{
return TRUE;
}
CExerciseApp theApp;
- Save All
12.1.10Dialog Box Methods...........................................................................
A dialog box is based on the CDialog class. As seen above, when creating your dialog
box, you can derive a class from CDialog. The CDialog class itself provides three
constructors as follows:
CDialog();
CDialog(UINT nIDTemplate, CWnd* pParentWnd = NULL);
CDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL);
The default constructor, CDialog(), can be used to declare a variable whose behavior is
not yet known or, for one reason or another, cannot yet be defined. When creating your
class, you should also declare at least a default constructor.
The identifier of the dialog box, such as IDD_DIALOG1, can be used as the first
argument, nIDTemplate, of a CDialog() constructor to create a dialog box from an
existing resource.
If you are using a Win32 template to create your dialog box, pass the name of this
template as a string to a CDialog() constructor, lpszTemplateName.
When implementing your default constructor, initialize the parent CDialog constructor
with the IDD enumerator declared in your class. If your dialog box has an owner, specify
it as the pParentWnd argument. If you set it to NULL, the application will be used as the
dialog’s parent.
If you dynamically create objects for your application using your dialog class, it is a good
idea to also declare and define a destructor. This would be used to destroy such dynamic
objects.
Most other methods of a dialog box depend on circumstances we have not yet reviewed
Practical Learning: Creating a Dialog Box
- Declare a default constructor and a destructor for your dialog class and implement
them as follows:
class CExerciseDlg : public CDialog