Visual C++ and MFC Fundamentals Chapter 12: Dialog-Based Windows
Practical Learning: Adding a Dialog Box to an Existing Application
- Start a new MFC Application project named SDIAndDlg
- Create it as a Single Document and click Finish
- To add a dialog box, on the main menu, click Project -> Add Resource...
- In the Add Resource dialog box, double-click Dialog
- To create a class for the new dialog box, right-click it and click Add Class...
- In the MFC Class Wizard, specify the Class Name as CExerciseDlg
- In the Base Class combo box, select CDialog and click Finish
- Display the menu by double-clicking IDR_MAINFRAME under the Menu folder of
the Resource View tab - Click View and click the first empty item under it. Type – and press Enter to add a
separator. - In the menu item under the new separator, type &Exercise... and press Enter
- Right-click the new Exercise menu item and click Add Event Handler...
- In the Message Type, access the COMMAND item. In the Class List, click
CMainFrame. Accept the Function Handler Name then click Finish Add And Edit - Change the file as follows:
#include "stdafx.h"
#include "SDIAndDlg.h"
#include "MainFrm.h"
#include "ExerciseDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
void CMainFrame::OnViewExercise()
{
// TODO: Add your command handler code here
CExerciseDlg Dlg;
Dlg.DoModal();
}
- Execute the application. On its main menu, click View -> Exercise...
- After using the dialog box, close it and close the application to return to MSVC
12.3 Property Sheets and Wizards.....................................................................
12.3.1..Introduction to Property Pages..........................................................
In some applications, you may want to add many but necessary and useful controls to a
dialog box. You can solve this problem in three main ways: