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

Expanding and collapsing Dialogs

By , 9 Jan 2000
 

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Michael Walz
Switzerland Switzerland
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralClevermemberkilowatt26 Mar '02 - 8:01 
Good job!
 
I think that your idea to set the expand and collapse boundaries of the dialog is clever and I like it.
 
There is one problem that I see though, when the dialog is collapsed, it is still possible to tab to the items that are out of view. In your demonstration app it is a little hard to tell this becuase there is only one tab point that is hidden (the radio buttons).
 

GeneralRe: ClevermemberDimitris Vassiliades15 Nov '02 - 8:48 
You could change a little the sources and provide a (pure) virtual function in CExpandDialog you can override to fit your dialog needs. Your problem could be solved by disabling all hidden controls and then re-enabling them when expanding.;)
e.g.

class CExpandDialog
{
...
protected:
virtual void OnExpandCollapse(BOOL bExpanded)
{
//Enable / Disable all controls shown / hidden
}
...
}

you also need to change CExpandDialog::OnExpandButton() to also call OnExpandCollapse. Something like:

void CExpandDialog::OnExpandButton()
{
  ...
  m_bIsExpanded = !m_bIsExpanded ;
  OnExpandCollapse(m_bIsExpanded);
  ...
}


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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 10 Jan 2000
Article Copyright 2000 by Michael Walz
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid