Click here to Skip to main content
6,634,665 members and growing! (18,921 online)
Email Password   helpLost your password?
Desktop Development » Dialogs and Windows » General     Intermediate License: The Code Project Open License (CPOL)

Expanding and collapsing Dialogs

By Michael Walz

This article gives you the ability to make your dialogs expand or contract, depending on how much information the user wishes to view.
MFC, Dev
Posted:9 Jan 2000
Views:87,541
Bookmarked:42 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
26 votes for this article.
Popularity: 6.53 Rating: 4.62 out of 5

1

2
1 vote, 8.3%
3
2 votes, 16.7%
4
9 votes, 75.0%
5

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


Member

Location: Switzerland Switzerland

Other popular Dialogs and Windows articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 17 of 17 (Total in Forum: 17) (Refresh)FirstPrevNext
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    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 9 Jan 2000
Editor: Smitha Vijayan
Copyright 2000 by Michael Walz
Everything else Copyright © CodeProject, 1999-2009
Web19 | Advertise on the Code Project