Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Expanding and collapsing Dialogs

0.00/5 (No votes)
9 Jan 2000 2  
This article gives you the ability to make your dialogs expand or contract, depending on how much information the user wishes to view.

Dialog in collapsed state

Dialog in expanded state

Sometimes it may be useful to show only the important part in a dialog and have a button usually labeled "More" that expands the dialog when the user clicks on it. Once the dialog is expanded, the "More" button displays "Less" and as soon as the user clicks on the "Less" button, the dialog will shrink to its initial size.

The CExpandDialog class performs this for you. All you have to to is add the DialogExpander.cpp file to your project and make some minor changes in your dialog class and template.

Modify the header file of your dialog class like this:

/////////////////////////////////////////////////////////////////////////////

// CExpandDialogDlg dialog


#include "DialogExpander.h"    //<<<< add here

...
class CExpandDialogDlg : public CDialog
{
...
protected:
...
    CExpandDialog m_ExpandDialog ;    //<<<< add here
...
}

Modify the OnInitDialog function dialog class like this:

BOOL CExpandDialogDlg::OnInitDialog()
{
    CDialog::OnInitDialog();


    m_ExpandDialog.Initialize(this, FALSE, IDC_MOREBUTTON, 
                    IDC_SHRINKMARK, IDC_EXPANDEDMARK,
                    IDC_LESSTEXT) ; //<<<< add here


    ...
}

With the class wizard, add a handler for the "More" button (e.g. OnMore()) and modify it like this:

void CExpandDialogDlg::OnMore() 
{
    m_ExpandDialog.OnExpandButton() ;
}

The dialog template must include two special static controls. One that indicates the position of the bottom of the dialog when it is in the collapsed state (1 on the legend below) and one that contains the string that should appear on the "More/Less" button when the dialog is in the expanded state (2 on the legend below). These two controls will not be shown because the CExpandDialog class will hide them automatically.

Dialog template

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