Click here to Skip to main content
Click here to Skip to main content

Stacked dialogs

, 29 Dec 1999
Rate this:
Please Sign up or sign in to vote.
Creating a stacked dialog such as Netscape's 'Preferences' dialog.

Sample Image - StackDialog.gif

Introduction

Most common solution to organize a large amount of information in a dialog box is to use a property sheet with a set of property pages. However, this approach has several problems:

  1. It is not easy to add controls to the property sheet (outside of property pages).
  2. Things become fuzzy if some background process needs to change the currently active page.

The alternative solution is to use a stacked dialog with any number of stacked pages. Stacked dialog is a simple dialog that contains any programmer defined set of controls. One of these controls is designated as a placeholder control (usually a picture control). Stacked page is a child dialog with any number and type of controls. Stacked dialog will position and resize all stacked pages according to the position and size of a placeholder control on a stacked dialog. Only one stacked page may be visible and active at any moment of time. Active stacked page is selected programmatically -- this may be done either by clicking on a dialog control (select page from a list box) or based on some event / trigger from the application.

Using stacked dialog in your application, you will achieve the following:

  1. Combine one of stacked pages with other controls.
  2. Change active page either on user action or programmatically based on application's internal state.
  3. Simple class interface

Each TStackedPage derived class may implement any of the following virtual functions:

  • OnCreatePage called once after the page is created
  • OnDestroyPage called once before the page is destroyed
  • OnSetActive called once the page becomes active
  • OnKillActive called once the page becomes inactive

TStackedDialog derived class must provide an implementation of the virtual abstract function OnPageChanged(). This is an ideal place to modify the appearance of the stacked dialog based on the deactivated/activated page.

Pictures from a demo application show a dialog box with 3 possibilities to select a page:

  1. from a listbox,
  2. from a combobox and
  3. clicking on a push-like radio button.

In the middle of the dialog are 2 pages: one with a calendar control and the other with a tree control.

Step 1:

Create a dialog. Place a picture control (placeholder) where you want to have stacked pages on your dialog. This control should be invisible and disabled. Also, place a control that will enable a user to choose the active page (for example, listbox or combobox).

Using class wizard, create a class for the new dialog. This class must be derived from TStackedDialog. Since TStackedDialog is an abstract class, add an implementation for the following TStackedDialog abstract virtual methods:

  • TStackedPage *CreatePage(UINT nId)
  • void OnPageChanged(UINT nId, BOOL bActivated)

Abstract virtual function CreatePage() is called to create a stacked page dialog based on its resource ID.

Step 2:

Create a dialog for each stacked page that you need. Each dialog should have the following properties:

  • Child
  • No border
  • Not visible
  • Disabled

Using class wizard, create a class for each stacked page. Each class must be derived from TStackedPage.

Step 3:

Within OnInitDialog() function of the stacked dialog class, add stacked pages to the stacked dialog.

...
AddPage(IDD_PAGE_1);
AddPage(IDD_PAGE_2);
...

Each AddPage() will execute the abstract virtual function of the base class (implemented in derived class) CreatePage() that should have the following implementation:

TStackedPage *CreatePage(UINT nId)
{
    switch (nId) {
    case IDD_PAGE_1: return new CPageOneDialog;
    case IDD_PAGE_2: return new CPageTwoDialog;
    }
    return NULL;
}

Step 4:

After adding all the pages to the stacked dialog, activate the initial page with the following line:

SetPage(IDD_PAGE_1);

Any previously activated page will be first deactivated. Use the same method to activate the page, as a response to a user action or based on internal application state.

SetPage() function will call an abstract virtual function TStackedDialog::OnPageChanged() implemented in the derived class. This is the best place to update the stacked dialog based on the currently active page.

Known problems

Manual movement through dialog controls (using Tab/Shift-Tab) is not working properly. I have not actually had the time to work on it. Anybody interested ...

Latest version may be downloaded here. Any comments or suggestions regarding the known problem are welcomed.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Zoran M. Todorovic
Web Developer SCA d.o.o.
Serbia Serbia
I am a cofounder of SCA Software, company that specializes in software for process control, visualization and communication. Programming for the last 10 years in C++, Delphi. Visual C++ for the last 6 years. Degree in Electronics Engineering and Telecommunications.

Comments and Discussions

 
Questionhow do i derive the sub class as TStackedPage? Pinmemberchatsash5-Jun-07 8:54 
Generalsolution of Tab problem Pinmemberxpmao11-Aug-04 15:06 
GeneralProblems when used in CFormView PinmemberOri K30-Oct-03 5:20 
GeneralRe: Problems when used in CFormView PinmemberOri K30-Oct-03 6:37 
GeneralAccessing TStackedPage Variables PinmemberJonah Bishop12-May-03 5:37 
GeneralRe: Accessing TStackedPage Variables Pinmemberhupe17-Jul-03 11:08 
QuestionHow to Access Controls on Stacked Dialog From Parent Dialog?? Pinmember-R-J-25-Apr-03 10:19 
AnswerRe: How to Access Controls on Stacked Dialog From Parent Dialog?? PinsussAnonymous28-Apr-03 9:15 
GeneralSub Dialogs in plugin DLLs Pinmemberalbuemil28-Jan-03 1:19 
GeneralTip for setting focus inside a pane PinmemberAanidaani18-Jan-03 23:07 
GeneralUsefull tip with radio buttons PinsussGezo24-Oct-02 21:42 
GeneralManual movement through dialog controls PinmemberJonMcDonough5-Sep-02 4:45 
QuestionHow to prevent other modeless dialogs from overlapping the main Dialog in a Dlg Based App PinmemberHawkeye7-Jun-02 16:02 
AnswerRe: How to prevent other modeless dialogs from overlapping the main Dialog in a Dlg Based App PinmemberTBiker8-May-03 4:42 
GeneralPerfect Pinmembersupertedusa22-May-02 7:26 
GeneralDialog navigation keys PinmemberShog95-Feb-02 13:31 
GeneralNo default button activity PinsussBraveg Whett16-May-00 17:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 30 Dec 1999
Article Copyright 1999 by Zoran M. Todorovic
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid