Solved

Creating Tabbed Dialogs Using MFC

Posted on 1997-09-07
4
2,768 Views
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  {
        DECLARE_DYNAMIC(CKingDlg)
 
 // Construction
 public:
        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"

IMPLEMENT_DYNAMIC(CKingDlg, CPropertySheet)

CKingDlg::CKingDlg(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
        :CPropertySheet(nIDCaption, pParentWnd, iSelectPage) {
        AddPage(&m_page1);
        AddPage(&m_page2);
        AddPage(&m_page3);
}
...

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:

BUT WHERE IN THE CODE?????

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.
0
Comment
Question by:theadmin090797
  • 2
4 Comments
 
LVL 4

Expert Comment

by:AVaulin
Comment Utility
The easiest way to understand what you want is adding "Property Sheet" component from "Component Gallery".
0
 

Accepted Solution

by:
Duebel earned 50 total points
Comment Utility
 Hi,
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();

to

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

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

Author Comment

by:theadmin090797
Comment Utility
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.
0
 

Author Comment

by:theadmin090797
Comment Utility
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.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
paragon account problem 9 96
Detect CR LF to each line 12 137
ShiftLeft challenge 21 65
Path of Workbook 3 44
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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 …
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now