Create and name multiple dialogs

Bryan Kelly 426 Reputation points
2024-07-27T04:03:54.8466667+00:00

Windows 11, VS 2022, version 17.7.6

The goal is to create a project with multiple dialogs.  I found the process to create some dialogs, but the dialogs cannot be renamed and when the dialogs are closed within the VS windows I cannot reopen it.

Here is my current status.

Each dialog is to be what I call an interactive drag and drop tool, meaning, the dialog is displayed within the Visual Studio framework and the user gets to use the Toolbox and drag and drop items onto the dialog.  For example, push buttons. 

Create an MFC Application, C++, Windows, Desktop

                Name it multi_dialog_4. 

Application Type: 

Dialog Based

Dialog based options <none> (my best guess)

Advanced Features:  Turn off ActiveX, not needed.

Set the name of the dialog.  Right click it and select Properties.  The name cannot be changed.  What are the steps to change the name?

Now to add a second dialog.

File -> New -> File -> … no option for a new dialog

File -> Add -> … not here

From the main tool bar click:  View -> Resource View, opens “Resource View – multi_dialog_4

Open these items:  multi_dialog_4 -> multidialog4.rc -> Dialog 

Right click on Dialog -> Add Resource and click on Dialog then New to get a new dialog.

Right click it to get Properties and go to Misc -> Name.  I cannot change the name.  What are the steps to change the name of this dialog?

Note also, because of my long names the names in the tabs for the two dialogs are identical.  This is a problem.

Now, just for the exercise, close both dialogs in the Visual Studio editor, then open them again.  To open them again, display the Resource view.  Open the group Dialog to find:

resource

Note that neither dialog is listed.  When I clicked IDRETRY one of the dialogs was displayed but the name was not shown.

In summary:

Have I found the right method to create new dialogs?

What are the steps to rename the dialogs?

What are the steps to open the dialogs after the edit window for them has been closed?

 

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,912 questions
{count} votes

Accepted answer
  1. RLWA32 48,151 Reputation points
    2024-07-27T07:01:37.7566667+00:00

    The Visual Studio dialog editor manages dialogs using their resource identifier (ID). What you see as the dialog Name in the property page is only a display name based on the dialog ID. If you change the dialog ID the display name will change accordingly.

    For example, create the multi_dialog_4 application as described above -

    multi4create

    Notice that the initial dialog had IDD_MULTI_DIALOG_4_DIALOG (based on the project name) as its initial dialog.

    Display the dialog properties -

    multi4props

    As you can see, the "Name" is based on the dialog's ID and cannot be directly edited.

    Now in the property page lets change the dialog ID to IDD_MULTI1 -

    multi1id

    At this point the dialog ID has been changed but the VS dialog editor has not refreshed the displayed "Name" yet.

    To have VS refresh the display "Name" first click the dialog id in the Resource View --

    multi1resview

    Now click back on the dialog image to show the property page again -

    multi1newname

    Now the displayed "Name" has been refreshed.

    And adding a new dialog as described above -

    multinewdlg

    If you change the new dialog's default ID from IDD_DIALOG1 to something else that you prefer you now know how to see that change reflected in the dialog editor.

    To reopen a closed dialog double-click on its ID in the resource view.


3 additional answers

Sort by: Most helpful
  1. RLWA32 48,151 Reputation points
    2024-07-27T12:17:00.63+00:00

    The proper way to add a dialog to an MFC application is as follows -

    Add a new Item to the project and select MFC->Add MFC Class

    NewMFC

    Configure the Add Class dialog to set CDialog (or CDialogEx) as the Base class and enter the dialog ID that you want to use -

    AddClass

    After you click OK the dialog resource will be added and the related .h and .cpp files for the MFC dialog class for that dialog will be created and added to your project.

    Added

    Your project now has everything it needs so that you can add controls to the dialog and customize it using Class Wizard and or context menus.

    Visual Studio automatically adds information to the dialog class header file that is used at design time to connect the dialog with the related code.

    WizardConnect

    After creating a dialog and the related .h and .cpp files if you later change the dialog resource identifier you must conform this information in the dialog's .h file.

    My advice to you is to use meaningful resource identifiers when you create dialogs and then leave them alone. That's the best way to ensure that Visual Studio's dialog and code wizards/editors function as intended.


  2. RLWA32 48,151 Reputation points
    2025-04-06T10:08:44.01+00:00

    @Bryan Kelly, Since this thread was started a year ago it has become long and confusing. I am using this Answer to summarize the guidance previously provided and again illustrate the proper way to add an additional MFC dialog to an MFC dialog-based application. All of the following was done with VS2022. Lets start with a newly created MFC dialog-based application project.

    MFCExampleApp

    In solution explorer select the project node and right click to open the context menus as shown here

    ContextMenu

    Upon clicking "New Item..." an "Add New Item" dialog will open. Expand the "Visual C++" node on the left and select "MFC" and also "MFC Class" as shown below. Give your new class a name. Here I use CAnotherDialog. Then click the Add button

    AddNewItem

    After clicking the Add button the "Add MFC Class" dialog will open. Change the Base class from CWnd to CDialog and provide a Dialog ID. Then click OK.

    AddMFCClass

    VS2022 will then create and add the CAnotherDialog.cpp file, the CAnotherDialog.h file and the IDD_ANOTHER_DIALOG dialog resource to the project.

    Solution explorer AFTER new MFC dialog added to the project

    SolutionExplorer

    Resource View after new MFC dialog added to the project

    ResourceView


  3. Bryan Kelly 426 Reputation points
    2025-04-08T03:18:54.2666667+00:00

    Answer RLWA32 post, Apr 6, 2025, 3:08 AM

    Create the same project name, build, run without changes, looks OK.

    The reverse color images you provide are a bit difficult to read.  After creating the project and running the unchanged project, open Resource View and the dialog options to reveal this.  Two items there.   The second opens the default dialog of the project.

    s01

    The second image shows Add –> New Item selected.  The third image shows a dialog to create a class.  However, when I select add -> New item, the result is not compatible with yours.

    s02

    Instead I use: Right click -> Add -> Class  to get this

    s03

    Close but clearly not the same.  Click OK.  Yes, the files were added.

    Go to resource view and it looks like this.

    s04

    It is not the same, nothing new was added.  No new dialog.

    From that view, right click on “Dialog” -> Add Resource -> Dialog -> New

    There is not immediate opportunity to change the name and the default name is IDD_DIALO1, noting that it is actually dialog 2.

    Here your instructions stop.  There is nothing about how to open the dialog.

    AND THAT IS THE WHOLE POINT!

    So I go a bit further.  Return to the first dialog, add a button, change its ID to ID_OPEN_DIALOG_2.  Right click on that new button and select option:  Add Event Handler …

    Take the defaults for the popup dialog: Event Handler and click OK.  This code is created and ready to edit.

    void CAboutDlg::OnBnClickedOpenDialog2()

    {

                // TODO: Add your control notification handler code here

    }

    So what is the code to open the second dialog?  Where should it be declared?

    Do ctl-F and search for IDD_DIALOG1 to get the below situation

    s05

    That should not happen.  But maybe its ok. Save, then build, then search again.  The only instance is in Resource.h and the constant:  #define IDD_DIALOG1

    That is not a class or object that can be opened.

     

    Two Questions

    First:  somewhere,…, there are some pages or instructions that describe class CDialog, and certainly all the default classes.  Somewhere,…, there are descriptions of all the functions of that class, and all the default classes.  Where can I find those descriptions?

    Second: I have added the second dialog and created the shown event handler to be called when the button is clicked.  What is all the code needed to open that dialog?


Your answer