0
votes

I am trying to build an MFC application Dialog based application. It runs ok. But I need to insert another Dialog. So how can I for example, pressing on a button from the first dialog to open the new added dialog?.

I am using Microsoft Visual Studio 2015.

  • I right clicked on the resources folder and insert a dialog.

It is inserted, but how to create it?.

Thank you.

2

2 Answers

4
votes

The easiest way is: I consider you are creating a Dialog based application so you get a main Dialog box and an About Dialog box when Selecting menu->About.

  • To add Another Dialog to your application:

1- Right click on the solution explorer on the resources files and select Add->Resource->Dialog->New

You get a new Dialog right front of you. Right click on this Dialog and select Add Class. give it for example a name like "MyDlg2" and click ok.

You'll see two files added: MyDlg2.h and MyDlg2.cpp.

Now How to Popup this second dialog (MyDlg2)? Let's create a button on the main Dialog:

  • Drag a button onto Main Dialog.
  • Give it a caption "Gong to Dialog2..."
  • Double-click this button to add a handler for it.
  • In this handler enter:

    MyDlg2 dlg;
    dlg.DoModal();
    
  • Scroll to the top of this file and add:

    #include "MyDlg2.h"
    

This is important so that main Dialog knows How to create dialog 2.

  • Build and run.
1
votes

You need to derive a class from CDialog. For more information check this MSDN example.