Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 12: Dialog-Based Windows


Practical Learning: Adding a Dialog Box to an Existing Application



  1. Start a new MFC Application project named SDIAndDlg

  2. Create it as a Single Document and click Finish

  3. To add a dialog box, on the main menu, click Project -> Add Resource...

  4. In the Add Resource dialog box, double-click Dialog

  5. To create a class for the new dialog box, right-click it and click Add Class...

  6. In the MFC Class Wizard, specify the Class Name as CExerciseDlg

  7. In the Base Class combo box, select CDialog and click Finish

  8. Display the menu by double-clicking IDR_MAINFRAME under the Menu folder of
    the Resource View tab

  9. Click View and click the first empty item under it. Type – and press Enter to add a
    separator.

  10. In the menu item under the new separator, type &Exercise... and press Enter

  11. Right-click the new Exercise menu item and click Add Event Handler...

  12. 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

  13. 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();
}


  1. Execute the application. On its main menu, click View -> Exercise...

  2. 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:
Free download pdf