How to Make MFC Dialog Boxes

A dialog box is a basic window derived from the CDialog class of the Microsoft Foundation Class (MFC) Library. You can use this example to understand dialog boxes by calling one dialog box from another. You'll first create a CDialog object through the project wizard, then store a second dialog as a resource and create from the Class Wizard a class associated to it.

Things You'll Need

  • Microsoft Visual C++ or Visual Studio .NET
  • Basic familiarity with the IDE
Show More

Instructions

    • 1

      Launch Microsoft Visual C++ 6.0 or Visual Studio .NET. Create a new MFC AppWizard (exe) project and name it "Dialogs." Make sure that "Dialog based" and "Use MFC in a Shared DLL" are selected. Delete the "TODO" label from the dialog box.

    • 2

      Add a second dialog box. Click "Project" and then "Add Resource." Select "Dialog" under "Resource type" and click "New."

    • 3

      Set up the second dialog box. Right-click on it and change its ID to "IDD_DIALOGBOX2" and its caption to "Second." Close the "Properties Dialog." Associate the second dialog with a class. Open the Class Wizard by pressing Ctrl+W. Select "Create a new class," enter "CSecondDialog" in the "Name" text box and select "CDialog" as its base class. Click "Finish."

    • 4

      Add functionality by placing a button on the first dialog from the controls toolbox. Do a right-click on that button. Make the ID "IDC_BUTTONSECOND" and change the caption to "Second." Double-click the button, accept the default function name and make the following changes in the code of the DialogsDlg.cpp file.



      Under the "TODO" comment enter:

      CSecondDialog m_D2;

      m_D2.DoModal();


      Include the "SecondDialog" definition file at the top:

      #include "SecondDialog.h"

    • 5

      Compile and run the code. Test the application to make sure it works.

Tips & Warnings

  • Dialog boxes are either "modal" or "modeless." A modal dialog box must be cancelled before the application can continue. A modeless dialog box allows work on other tasks.

  • The second dialog is an example of a modal window. The first dialog is an example of a modeless window.

Related Searches:

Resources

Comments

You May Also Like

  • How to Use a Combo box in MFC

    A combo box control shows a list of strings in drop-down menu style. Providing a way to show multiple options while saving...

  • How to Use Edit Controls in MFC

    In Microsoft Windows based systems the CEdit class provides the functions of the edit controls in MFC. In a dialog based program...

  • How to Create MFC Events

    The MFC Library provides an evolution of the Exception Handling Model of plain C++. In Visual C++ the user is able to...

  • How to Make MFC Command Buttons

    "CButton" is the MFC class that allows programmers to manipulate command buttons. Command buttons are ubiquitous in programs with a graphical user...

  • What Is a Windows Dialogue Box?

    A dialog box is a temporary, separate window in a graphical user interface (GUI) that appears to either request information from a...

  • How to Use a Listbox Control in MFC Visual C++

    A list box is a Windows control that can display text or iconic items as a list of rows. The Microsoft Foundation...

  • How to Create Menus in MFC

    The MFC Library offers 2 methods of creating menus. This tutorial focuses on the Resource option. The other is the Dynamic Menu...

  • How to Close a Dialog Box

    If you're new to PC computing, working with active windows is straightforward. You can click within a window to perform basic operations,...

  • How to Create Message Maps in MFC

    A Windows operating system is message driven environment. An event like a mouse click or a printer signal sends a message to...

  • MFC ActiveX Tutorial

    The ActiveX Control program is used by programmers to configure how different applications communicate and share information. ActiveX can be used with...

  • How to Use checkboxes in MFC

    A checkbox control has two states, "checked" and "unchecked." It can be applied wherever a choice is expected of the user, such...

  • How to Make an MFC Worker Thread

    Threads are the objects that make multi-tasking possible. Threads, each corresponding to a "time slice" or separate state of the running program,...

  • How to Close Open Dialog Boxes

    A dialog box is a rectangular box that opens up on your computer when your computer or an installed program needs to...

  • How to Make Dialog Boxes in Excel Visual Basic

    When writing a program in the Visual Basic editor of Microsoft Excel you may find that you need to show dialog boxes...

  • What Are Dialog Boxes?

    Dialog boxes provide two main functions: alerting a user to important program information and allowing the user to set options. Dialog boxes...

  • How to Move on After a Relationship Ends

    Some breakups you can see coming, while others come as a total surprise. Whatever the case, breakups are never easy. Your routine...

  • How to Replace Brother MFC Printer Ink

    Brother MFC printers are very commonly used for many different types of printing needs. There are numerous models to choose from. You...

  • ActiveX Component Tutorial

    An ActiveX component is an applet that can be downloaded and run independently in Microsoft's Web browser. It can also be "plugged...

  • How to Remove the Password Dialog Box From Windows

    By default, Windows boots to the Welcome screen or, in the case of versions of Windows older than XP, to a password...

  • C MDI Tutorial

    Multiple Document Interface (MDI) is an application architecture that allows the user to open multiple "documents" or windows of the same form,...

Related Ads

Featured