Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2963
  • Last Modified:

Creating Tabbed Dialogs Using MFC

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
theadmin090797
Asked:
theadmin090797
  • 2
1 Solution
 
AVaulinCommented:
The easiest way to understand what you want is adding "Property Sheet" component from "Component Gallery".
0
 
DuebelCommented:
 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
 
theadmin090797Author Commented:
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
 
theadmin090797Author Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now