Go Premium for a chance to win a PS4. Enter to Win


Creating Tabbed Dialogs Using MFC

Posted on 1997-09-07
Medium Priority
Last Modified: 2013-11-20
How do I create a tabbed dialog in MFC that has the look and feel of the ones you find in Windows 95?
I have posted messages for this question and have never really gotten an answer, most books I have seen tell you how to create the tabbed dialogs with an SDI. But that is not what I want, I want just the tabbed window when the program is executed.

i.e. right click on the windows 95 desktop and select properties

The following lines is what I came up with while the entire web, it does not do me any good cause parts are missing.  Since I dont have much experience in Visual C++ this is a project I really want to accomplish, but I dont know how.

Creating Property Pages

(1) do I create a dialog based application first ????

1.In the Microsoft Developer Studio, select the Resource View tab.
2.Right Click on the Dialog folder.
3.Select the Insert Dialog menu option from the popup menu.
4.You should now have a new dialog resource with a default name like IDD_DIALOG1. Feel free to rename it to a more meaningful name. You may also want to remove the OK and Cancel buttons being that this will be a tab in a dialog which will contain that functionality outside of the tabs. Next, you could add all the controls (radio buttons, listboxes, etc.) that you want to appear on that tab. Also, the dialog caption becomes the tab caption, so it is a good idea to change the caption at this point to the name that you want to appear in the tab.

what about the properties for the dialog box (child, thin etc)

5.Use the Class Wizard to generate your CPropertyPage derived class that incorporates your new dialog resource. If you invoke Class Wizard while the focus is on a new dialog resource, Class Wizard will assume your intention is to create a new class for this resource, and will prompt you. If that is the case click on the OK button and follow the remaining steps in Class Wizard to generate your class. Most importantly, do not forget to change the Base Class to CPropertyPage in the Class information frame.

Creating a Property Sheet

1.Use the Class Wizard to generate a new CPropertySheet derived class. When the "Create New Class" dialog appears ensure that the Base Class you select is CPropertySheet.
2.Click the "Create" button and your new Property Sheet class will be created.

Putting it all together

Up until this point you have managed to practically create a tabbed dialog without writing a single line of code by making use of the Resource Editor and the Class Wizard; however, this is where the Wizards stop on this journey. Now the programmer must finish the job. To successfully display a multi-tabbed dialog, you should:

Include all CPropertyPage derived object variables as data members of your CPropertySheet derived classed.

 // KingDlg.h : header file
 #include proppage1.h
 #include proppage2.h
 #include proppage3.h
 class CKingDlg : public CPropertySheet  {
 // Construction
        CKingDlg(UINT nIDCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);       ...
 // The objects vars for pages/tabs in KingDlg  public:
        CPropPage1 m_page1;
        CPropPage2 m_page2;
        CPropPage3 m_page3;

After constructing the CPropertyPage object variables [which will happen automatically if they are defined as objects as opposed to pointers to objects], call CPropertySheet::AddPage(CPropertyPage* pPage) for each object variable in the constructor of CPropertySheet.

// KingDlg.cpp : implementation file

#include "stdafx.h"
#include "tabs.h"
#include "KingDlg.h"


CKingDlg::CKingDlg(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
        :CPropertySheet(nIDCaption, pParentWnd, iSelectPage) {

Finally elsewhere in your code you may declare a variable of type CKingDlg that will display results of your creation upon a call to DoModal or Create. For instance:


CKingDlg kingDlg;

kingDlg.DoModal(); // multi-tab dialog appears!!!

The above has a lot of missing areas, I would really like a step by step solution on how to do this.  I asked a few people who do Visual C++ and they did not know how to create the tabbed dialogs.

Any help is greatly appreciated.

Thanks in advance.
Question by:theadmin090797
  • 2

Expert Comment

ID: 1305885
The easiest way to understand what you want is adding "Property Sheet" component from "Component Gallery".

Accepted Solution

Duebel earned 100 total points
ID: 1305886
I don't know if you want to create a Tab Dialog or a Property Page? I mean with or without the OK, Cancel and Apply buttons? Anyway. To create a property sheet is a fairly simple task with VC++. You want to create a dialog based app with a tab sheet inside. Right? Here is what you will have to do:
1. Create as many dialog as you like (will be the tabs). Their captions will be the text you will see in the tab controls.
2. Create for each dialog resource you just added a derived class from CPropertyPage (put all into the same file).
3. Create a new class derived from CPropertySheet (put into the same file).
4. Put into the definition of the CPropertySheet class data members for each PropertyPage. Declare them as private. (for example "CPage1 m_page1;")
5. Add to the constructor of the propertysheet class (the one with the LPCTSTR variable) the AddPage(&m_page) command for each propertypage.

This was the procedure for the property sheet. Now here is what to do to show the dialog:
1. Remove the pre created dialog class. and the pre created dialog resource. delete the corresponding file.
2. remove the include declaration from the main app file.
3. include the propertysheet header file.
4. in initinstance remove the pre generated dialog class declaration and replace it with the property sheet class declaration:
CMyAppDlg dlg;
 m_pMainWnd = &dlg;
 int nResponse = dlg.DoModal();


CTab dlg("My caption");
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();

Ok, that should be all. Hope I forgot nothing.

Author Comment

ID: 1305887
This is really a cool example but there are too many things in between thats missing.  Can someone explain this to a person who does not know Visual C++ very well, lets say you are giving someone directions on the phone how will you explain it to them step by step.  This is what I am trying to get here.

Author Comment

ID: 1305888
This is really a cool example but there are too many things in between thats missing.  Can someone explain this to a person who does not know Visual C++ very well, lets say you are giving someone directions on the phone how will you explain it to them step by step.  This is what I am trying to get here.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question