Chapter 12: Dialog-Based Windows Visual C++ and MFC Fundamentals
As done with the CDialog constructor, the nIDTemplate parameter is the identifier you
used when visually creating the dialog resource. If you are using a dialog box from a
template, specify its name as the lpszTemplateName argument. In order to effectively use
a modeless dialog box, it must be called from another window. Otherwise you can just
create a regular dialog box. The object from which you will be calling the dialog box is
also responsible for closing it (or "cleaning" it). Therefore, the class that calls the
modeless dialog box "owns" it. This means that you can specify it as the pParentWnd
argument.
When creating a modeless dialog box, declare a pointer to its class. Then call the
Create() method, passing the identifier or the template being used. You can do this in the
constructor of the class that will be its parent. Here is an example:
CDialog5Dlg::CDialog5Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CDialog5Dlg::IDD, pParent)
{
CCoolMode* Cool = new CCoolMode();
Cool->Create(IDD_DLG_MDLS,this);
}
To formally display the object, you have various options. When creating it, at design
time, you can set its Visible property to True (actually you would be applying the
WS_VISIBLE style). If you did not make it visible, or if the modeless dialog box is
hidden at a particular time, you can programmatically display it.
Practical Learning: Using Dialog Box Methods
- To add a new dialog box, display the Add Resource dialog box and double-click
Dialog - Click the OK button and press Delete twice to dismiss both the OK and the Cancel
buttons - Using the Properties window, change the ID of the dialog box to
IDD_DLG_FLOATER and its Caption to Floater - Check the Visible check box or set it to True
- Check the Tool Window check box or set it to True
- Set the Border property to Resizing
- Add a class for the dialog box. Call it CFloaterDlg and base it on the CDialog class