|

It is unusual to have a dialog-based application. This
is because a dialog box is usually made to complement a frame-based
application. In that case, after adding the dialog box to the application,
you would also provide the ability to call
the dialog from an SDI. In the same way, if you create an application made of various dialog
boxes, at one time, you may want the user to be able to call one dialog
box from another. To start, you would create the necessary dialog boxes.
To call one dialog box from another, in the header
file of the class of the calling dialog box, you can include the header
file of the class of the called dialog box. In the section where you want
to call the dialog box, you can declare
a variable of that other dialog box' class and call its CDialog::DoModal()
method.
|
Practical Learning: Calling One Dialog Box From Another
|
| |
- Start Microsoft Visual C++ .NET or MS Visual Studio .NET
- Create a new MFC Application named Primary1
- Create it as Dialog Based

- Set the Dialog Title to Calling One Dialog Box From Another

- Click Finish
- To add another dialog box, on the main menu, click Project -> Add
Resource...
- In the Add Resource dialog box, double-click Dialog
- Change the ID of the new dialog to IDD_SECOND_DLG and its Caption
to Second
- Right-click the dialog box and click Add Class...
- Set the Class Name to CSecondDlg and base it on CDialog
- Click Finish
- From the Class View, double-click the IDD_PRIMARY1_DIALOG
- Using the Toolbox, add a Button to the dialog box and change its
properties as follows:
Caption: Second
ID: IDC_SECOND_BTN
- Double-click the new Second button and implement its event as follows:
// Primary1Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "Primary1.h"
#include "Primary1Dlg.h"
#include ".\primary1dlg.h"
#include "SecondDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CPrimary1Dlg dialog
. . . No Change
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CPrimary1Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CPrimary1Dlg::OnBnClickedSecondBtn()
{
// TODO: Add your control notification handler code here
CSecondDlg Dlg;
Dlg.DoModal();
}
|
- Test the application
|
|