5,667,575 members and growing! (12,468 online)
Email Password   helpLost your password?
Desktop Development » Dialogs and Windows » General     Intermediate

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.
C++Windows, NT4, MFC, Visual Studio, Dev

Posted: 9 Jan 2000
Updated: 9 Jan 2000
Views: 79,282
Bookmarked: 33 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
26 votes for this Article.
Popularity: 6.12 Rating: 4.33 out of 5
1 vote, 8.3%
1
0 votes, 0.0%
2
1 vote, 8.3%
3
1 vote, 8.3%
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 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

About the Author

Michael Walz



Location: Switzerland Switzerland

Other popular Dialogs and Windows articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 16 of 16 (Total in Forum: 16) (Refresh)FirstPrevNext
GeneralAnother methodmemberSteve Mayfield21:06 22 Sep '03  
GeneralRe: Another methodmemberobjects6:05 2 May '06  
GeneralAny examples of using the expand feature with CPropertySheetmemberSuperD11:55 1 Aug '03  
Generalnew usagememberjohn john mackey12:58 12 Feb '03  
Generalbeautymemberlaue15:20 29 Jan '03  
GeneralClevermemberkilowatt9:01 26 Mar '02  
GeneralRe: ClevermemberDimitris Vassiliades9:48 15 Nov '02  
GeneralControls in expanded/collapsed areamemberjohn john mackey11:46 7 Jan '02  
GeneralRe: Controls in expanded/collapsed areasussAnonymous7:01 5 Jul '03  
GeneralA more efficient way...sussLX22:43 25 Oct '00  
GeneralRe: A more efficient way...memberDimitris Vassiliades10:03 15 Nov '02  
GeneralRe: A more efficient way...memberMatban5:38 9 Jan '04  
GeneralYou forgot tosussDaniel BERMAN7:05 10 Apr '00  
GeneralRe: You forgot tomemberUwe Keim22:48 30 Dec '01  
GeneralRe: You forgot tomemberDimitris Vassiliades10:10 15 Nov '02  
GeneralRe: You forgot tomemberMatban5: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-2008
Web08 | Advertise on the Code Project