Click here to Skip to main content
11,487,793 members (76,193 online)
Click here to Skip to main content

Tagged as

Expanding and collapsing Dialogs

, 9 Jan 2000 CPOL 116.2K 3.4K 64
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Michael Walz

Switzerland Switzerland
No Biography provided

Comments and Discussions

 
QuestionWant to shrink till Ok button Pin
Member 1072123818-Dec-14 2:43
memberMember 1072123818-Dec-14 2:43 
GeneralMy vote of 4 Pin
Adi Shavit14-Dec-11 0:50
memberAdi Shavit14-Dec-11 0:50 
GeneralVertical/horizontal (default) option Pin
varandas7928-Jul-09 0:46
membervarandas7928-Jul-09 0:46 
GeneralAnother method Pin
Steve Mayfield22-Sep-03 21:06
memberSteve Mayfield22-Sep-03 21:06 
GeneralRe: Another method Pin
objects2-May-06 6:05
memberobjects2-May-06 6:05 
GeneralAny examples of using the expand feature with CPropertySheet Pin
SuperD1-Aug-03 11:55
memberSuperD1-Aug-03 11:55 
Generalnew usage Pin
john john mackey12-Feb-03 12:58
memberjohn john mackey12-Feb-03 12:58 
Generalbeauty Pin
laue29-Jan-03 15:20
memberlaue29-Jan-03 15:20 
GeneralClever Pin
kilowatt26-Mar-02 9:01
memberkilowatt26-Mar-02 9:01 
GeneralRe: Clever Pin
Dimitris Vassiliades15-Nov-02 9:48
memberDimitris Vassiliades15-Nov-02 9:48 
GeneralControls in expanded/collapsed area Pin
john john mackey7-Jan-02 11:46
memberjohn john mackey7-Jan-02 11:46 
GeneralRe: Controls in expanded/collapsed area Pin
Anonymous5-Jul-03 7:01
sussAnonymous5-Jul-03 7:01 
GeneralA more efficient way... Pin
LX25-Oct-00 22:43
sussLX25-Oct-00 22:43 
GeneralRe: A more efficient way... Pin
Dimitris Vassiliades15-Nov-02 10:03
memberDimitris Vassiliades15-Nov-02 10:03 
GeneralRe: A more efficient way... Pin
Matban9-Jan-04 5:38
memberMatban9-Jan-04 5:38 
GeneralYou forgot to Pin
Daniel BERMAN10-Apr-00 7:05
sussDaniel BERMAN10-Apr-00 7:05 
GeneralRe: You forgot to Pin
Uwe Keim30-Dec-01 22:48
memberUwe Keim30-Dec-01 22:48 
GeneralRe: You forgot to Pin
Dimitris Vassiliades15-Nov-02 10:10
memberDimitris Vassiliades15-Nov-02 10:10 
GeneralRe: You forgot to Pin
Matban9-Jan-04 5:48
memberMatban9-Jan-04 5:48 
I don't think that this is a problem either. I have a similar dialog and when it is collapsed tab does not set focus onto the hidden controls even though I have not explicitly disabled them.

Matt

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.

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