Virtual Developer Workshop: Containerized Development with Docker

Sample Image

Environment: VC6 SP2, NT4 SP5

Most common solution to organize a big 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 appereance 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 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 from www.scasoftware.com. Any comments or suggestions regarding the known problem are welcomed.


Download demo project - 17 Kb
Download source - 3 Kb


  • Just what I was looking for. Thanks!

    Posted by mitcheljh on 07/10/2008 06:00am

    Nice job and good explanation.

  • WM_TIMER not received?

    Posted by Legacy on 05/09/2003 07:00am

    Originally posted by: kirkb

    My page's OnTimer() isn't getting called when the page is active, but IS getting called when it's inactive. Any ideas?

  • Awesome Work!!!!

    Posted by Legacy on 02/26/2003 08:00am

    Originally posted by: Richard 'vajuras' Osborne

    This is literally an anwser to a prayer. Thanks for this excellent code!!!!

  • Tab Problem

    Posted by Legacy on 09/13/2002 07:00am

    Originally posted by: Paul

    Very nice control thankyou.

    I have slightly reworked the example in the manner suggested by Mike Liss (2000/08/17), and the tab sequence through the controls works fine, with one exception.
    If I change _pages_ by clicking on the page 1,2,3 buttons the program hangs. All other methods of navigating pages works fine.
    I can resolve this by removing the "control" style setting from the dialog pages, but then loose correct tab control.

    Does anyone have any ideas.

  • exit code

    Posted by Legacy on 05/25/2002 07:00am

    Originally posted by: jay

    This set of classes is exactly what I was looking for. One question though. When I run your demo in debug mode the exit code it 0x2 which by the definition of the MSDN says its a program error meaning one of the following:

    1. A syntax error in the makefile
    2. An error or exit code from a command
    3. An interruption by the user

    Any sort of errors worry me as it could possibly lead to problems with the program when in use though I haven't had any problems so far with it. Do you know the reason it's returning this and a way to fix it?

    Thank you again for these classes.

    - jay

    edit: only occurs when using the close button in the upper right-hand corner of the main dialog box. Pressing cancel will return an exit code of 0x0

  • Does it support muti place holder?

    Posted by Legacy on 04/06/2002 08:00am

    Originally posted by: Liye Fang

    If there is more than one place holder needed for my program what should I do then?

  • Passing Parameters in and out of the Stacked Pages

    Posted by Legacy on 12/11/2001 08:00am

    Originally posted by: Saradhi

    One of the primary use of the Property Sheet is that the user can pass the values in and out of the property pages very easily.

    How can you pass on the values of the parameters from the in and out of the pages.

    For example I may have a page whhich contains some Edit Box and I'll set that Edit Box value.

    I need to get the value of that Box when I closes this stacked dialog and I want to use it in my program basically this is a preferences dialog box.

    Alos I wanted to pass some initila value to some of the control while activating this Stacked Dialog Box.

    Anyone has the idea how to doit???
    Expecting a quick response....

  • Help, can't see dialogs in SDI with dialog bar

    Posted by Legacy on 11/15/2001 08:00am

    Originally posted by: AMW

    Sometimes I think I should get an easier hobby.
    What I'm trying to do is add the stacked dialogs to a dialog bar of an SDI application.
    I'm pretty sure that I've typed everything correctly and the program compiles and links correctly, but when I run the app, my dialogs don't appear in the static control of the dialog bar.
    As I'm still kind of new to MFC, any kind of help would really be appreciated.
    Thanks in advance

  • A Problem!

    Posted by Legacy on 09/25/2001 07:00am

    Originally posted by: JC


    Anyone knows why error message "TStackedDialog base class undefined" is displayed after build?

  • Great article

    Posted by Legacy on 07/03/2001 07:00am

    Originally posted by: Flair bar

    This is realy a great one.
    Keep on

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date