Click here to Skip to main content
13,408,620 members (47,575 online)
Click here to Skip to main content
Add your own
alternative version


44 bookmarked
Posted 29 Dec 1999

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


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.


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:


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.


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.

You may also be interested in...

Comments and Discussions

Questionhow do i derive the sub class as TStackedPage? Pin
chatsash5-Jun-07 9:54
memberchatsash5-Jun-07 9:54 
Generalsolution of Tab problem Pin
xpmao11-Aug-04 16:06
memberxpmao11-Aug-04 16:06 
GeneralProblems when used in CFormView Pin
Ori K30-Oct-03 6:20
memberOri K30-Oct-03 6:20 
GeneralRe: Problems when used in CFormView Pin
Ori K30-Oct-03 7:37
memberOri K30-Oct-03 7:37 
GeneralAccessing TStackedPage Variables Pin
Jonah Bishop12-May-03 6:37
memberJonah Bishop12-May-03 6:37 
GeneralRe: Accessing TStackedPage Variables Pin
hupe17-Jul-03 12:08
memberhupe17-Jul-03 12:08 
QuestionHow to Access Controls on Stacked Dialog From Parent Dialog?? Pin
-R-J-25-Apr-03 11:19
member-R-J-25-Apr-03 11:19 
AnswerRe: How to Access Controls on Stacked Dialog From Parent Dialog?? Pin
Anonymous28-Apr-03 10:15
sussAnonymous28-Apr-03 10:15 
GeneralSub Dialogs in plugin DLLs Pin
albuemil28-Jan-03 2:19
memberalbuemil28-Jan-03 2:19 
GeneralTip for setting focus inside a pane Pin
Aanidaani19-Jan-03 0:07
memberAanidaani19-Jan-03 0:07 
GeneralUsefull tip with radio buttons Pin
Gezo24-Oct-02 22:42
sussGezo24-Oct-02 22:42 
GeneralManual movement through dialog controls Pin
JonMcDonough5-Sep-02 5:45
memberJonMcDonough5-Sep-02 5:45 
QuestionHow to prevent other modeless dialogs from overlapping the main Dialog in a Dlg Based App Pin
Hawkeye7-Jun-02 17:02
memberHawkeye7-Jun-02 17:02 
AnswerRe: How to prevent other modeless dialogs from overlapping the main Dialog in a Dlg Based App Pin
TBiker8-May-03 5:42
memberTBiker8-May-03 5:42 
GeneralPerfect Pin
supertedusa22-May-02 8:26
membersupertedusa22-May-02 8:26 
GeneralDialog navigation keys Pin
Shog95-Feb-02 14:31
memberShog95-Feb-02 14:31 
GeneralNo default button activity Pin
Braveg Whett16-May-00 18:36
sussBraveg Whett16-May-00 18:36 

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

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

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