Click here to Skip to main content
Licence CPOL
First Posted 9 Jan 2000
Views 100,315
Downloads 2,300
Bookmarked 54 times

Expanding and collapsing Dialogs

By Michael Walz | 9 Jan 2000
This article gives you the ability to make your dialogs expand or contract, depending on how much information the user wishes to view.

1

2
1 vote, 6.7%
3
3 votes, 20.0%
4
11 votes, 73.3%
5
4.70/5 - 29 votes
1 removed
μ 4.61, σa 1.07 [?]

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


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. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 4 PinmemberAdi Shavit0:50 14 Dec '11  
GeneralVertical/horizontal (default) option Pinmembervarandas790:46 28 Jul '09  
GeneralAnother method PinmemberSteve Mayfield21:06 22 Sep '03  
GeneralRe: Another method Pinmemberobjects6:05 2 May '06  
GeneralAny examples of using the expand feature with CPropertySheet PinmemberSuperD11:55 1 Aug '03  
Generalnew usage Pinmemberjohn john mackey12:58 12 Feb '03  
Generalbeauty Pinmemberlaue15:20 29 Jan '03  
GeneralClever Pinmemberkilowatt9:01 26 Mar '02  
GeneralRe: Clever PinmemberDimitris Vassiliades9:48 15 Nov '02  
GeneralControls in expanded/collapsed area Pinmemberjohn john mackey11:46 7 Jan '02  
GeneralRe: Controls in expanded/collapsed area PinsussAnonymous7:01 5 Jul '03  
GeneralA more efficient way... PinsussLX22:43 25 Oct '00  
GeneralRe: A more efficient way... PinmemberDimitris Vassiliades10:03 15 Nov '02  
GeneralRe: A more efficient way... PinmemberMatban5:38 9 Jan '04  
GeneralYou forgot to PinsussDaniel BERMAN7:05 10 Apr '00  
GeneralRe: You forgot to PinmemberUwe Keim22:48 30 Dec '01  
GeneralRe: You forgot to PinmemberDimitris Vassiliades10:10 15 Nov '02  
GeneralRe: You forgot to PinmemberMatban5:48 9 Jan '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web03 | 2.5.120209.1 | Last Updated 10 Jan 2000
Article Copyright 2000 by Michael Walz
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid