Virtual Developer Workshop: Containerized Development with Docker

Environment: VC6, win2000

It is not uncommon to need a dialog box that can change its appearance based on selections made within the dialog box. (Hence the need for tab and property sheets.) Often, tab controls or property sheets can be used to accomplish such dynamic behavior. Sometimes, however, there are so many possible selections and combinations of selections, that tab or property sheets are impractical. This technique shows a simple example of how to dynamically change a dialog box based on the selection of a list box. The CDynamicDlgDlg::Initialize() method shown below is called from the CDynamicDlgDlg::OnInitDialog() method. Each of the CDialogs in the CDialogStructure shown below is a dialog class with CHILD and THIN_FRAME properties. This could also be done in an array of CDialogs, but then functions and attributes specific to the "new" dialog classes would not be available.
typedef struct 
        CButtonDlg      buttonDlg;
        CRadioDlg       radioDlg;
        CStaticTextDlg  staticTextDlg;

typedef enum

void CDynamicDlgDlg::Initialize()
    CDialog*  dlg;
    numDlgs = NUM_DLGS;
    currentDlg = BUTTON_DLG;
    CRect     currentDlgRect, parentDlgRect;

    dialogStructure.buttonDlg.Create(IDD_BUTTON_DLG, this);
    dialogStructure.radioDlg.Create(IDD_RADIO_DLG, this);
    dialogStructure.staticTextDlg.Create(IDD_STATIC_TEXT_DLG, this);

    GetClientRect(parentDlgRect);   //parentDlgRect = GetMyRectangle();
    for(int i = 0; i < NUM_DLGS; i++)
        dlg = GetDlgAt(currentDlg);
        dlg->SetWindowPos((const CWnd*)&wndTop,
                      (parentDlgRect.right-currentDlgRect.right)/2, \
                      (parentDlgRect.bottom - currentDlgRect.bottom)/2, \
        currentDlg = currentDlg + 1;
    currentDlg = BUTTON_DLG;

CDialog* CDynamicDlgDlg::GetDlgAt(int dlgType)
    case BUTTON_DLG:
        return &dialogStructure.buttonDlg;      
    case RADIO_DLG:
        return &dialogStructure.radioDlg;
        return &dialogStructure.staticTextDlg;
        return NULL;

void CDynamicDlgDlg::OnSelchangeDialogDropList() 
    CDialog* dlg;
    dlg = GetDlgAt(currentDlg);
    dlg = GetDlgAt(dialogType);
    currentDlg = dialogType;


Download demo project - 37.3 KB Kb


  • Powerful.

    Posted by Legacy on 06/26/2003 07:00am

    Originally posted by: Gigi

    I am headache for the same problem I have. Now I got the solution. Thanks

  • Escape key and Enter key closes the inner dialog box, when it has focus

    Posted by Legacy on 04/04/2003 08:00am

    Originally posted by: sam

    There is a serious problem, when we use this approach!
    for instance, in this example, in the radio button dialog box, select one of the radio button and then press escape key or enter key, that radio button dialog box vanishes in the air, but the parent dialog box still exists.

    Is there any solution, anybody can give?????

  • Good Job!

    Posted by Legacy on 12/20/2002 08:00am

    Originally posted by: Davis

    It's very useful.
    Thanks a lot!

  • Re: Why not use tabs?

    Posted by Legacy on 10/11/2002 07:00am

    Originally posted by: Jacques Du Biel

    The comments raised here are all valid. Yes, using Property Sheets and Property Pages may be the preferred way to go as specified in Windows UI design guidelines. Let's consider this : Why do Microsoft deviate from the guideline regarding this approach? You can simply have a look at the Scheduled Task Properties dialog in 'Scheduled Tasks'. It follows this exact approach. Is it the best way to implement this functionality? Probably not. The fact of the matter is, it may be required or even desired in some cases.

  • will never be used

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

    Originally posted by: ugly

    what you did was an attempt to rewrite property sheet, but in ugly way and waste of time. if you think that having lots of property pages is not the way to go (while you are indeed need them) go back to procedural languages.
    suggestion is to improve what we have with property sheet with features, such as side tabs, toolbars, tree control (all are on property sheet area) for reloading different set of pages, etc.
    keep looking in codeguru, you find lots of excellent ideas and sample codes. sure.

  • Why not use tabs?

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

    Originally posted by: Peter Ritchie

    Why would you not use tabs in a circumstance like this?

    The Windows UI design guildlines would suggest that a Tab control should used in circumstances like this.

    You're overridding the basic functionality of a combo-box/dropdown and causing it to perform (or to have a side-effect) that is not common. The use of a dropdown in this way is counter-intuitive. This makes the interface harder to understand and learn--without adding any more value.

  • 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