Solved

Creating Tabbed Dialogs Using MFC

Posted on 1997-09-07
4
2,879 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:AVaulin
ID: 1305885
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
ID: 1305886
 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
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.
0
 

Author Comment

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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

617 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