Solved

expand dialog

Posted on 2001-08-19
12
349 Views
Last Modified: 2013-11-20
i'd like to expand my dialog to display more information, for example incase the user click the button "Advance", the dialog's height is doubled and there are several controls which are addes at the bottom in a nice frame.
how to do it?
your help is appreciated.
0
Comment
Question by:web37
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Design the dialog box in its "Details" (large size) mode.  

Then, in OnInitDialog(), add lines like:

///// in CMyDlg.h...
   CRect m_rcFullSize;
   CRect m_rcHalfSize;
   BOOL  m_fFullSize;

////// in OnIntDialog()...
GetWindowRect( &m_rcFullSize );
m_rcHalfSize= m_rcFullSize;
m_rcHalfSize.bottom -= 100;
MoveWindow( &m_rcHalfSize );
m_fFullSize= FALSE;

In this example, I just shortened the window by an arbitrary 100 pixels.  In my actual implementation, I look at a particular control in the dialog box, then use its location to decide how much to shorten the window.

In your OnDetails() handler, toggle m_fFullSize and use MoveWindow to set the right size.  To wit:

void CMyDlg::OnDetails()
{
    m_fFullSize= !m_fFullSize;
    if (m_FullSize) {
        MoveWindow( m_rcFullSize );
        GetDlgItem(IDC_BtnDetails)->SetWindowText("No &Details");
    }
    else {
        MoveWindow( m_rcHalfSize );
        GetDlgItem(IDC_BtnDetails)->SetWindowText("&Details");
    }
}

-- Dan
0
 
LVL 32

Expert Comment

by:jhance
Comment Utility
0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
add this dialog to your project:

//header file



// Expanding and collapsing dialogs
//
// Michael Walz (walz@epsitec.ch)
// Dec. 99
//

#ifndef _INC_EXPANDDLG_H_
#define _INC_EXPANDDLG_H_

class CExpandDialog
{
     BOOL m_bIsInitialized;
     BOOL m_bIsExpanded;
     int m_IdExpandButton;
     int m_IdCollapsedMark;
     CWnd *m_pDialog;
     CString m_sTextMore;
     CString m_sTextLess;
     CRect m_dialogrect;

public:
     CExpandDialog();

// call this function from the OnInitDialog() function
     void Initialize(CWnd *pDialog,               // pointer to dialog
                      BOOL bInitiallyExpanded,     // TRUE => dialog is initially expanded
                      int IdExpandButton,          // id of " More " / " Less " button
                      int IdCollapsedMark);          // id of static that indicates position of
                                                       // the bottom of the collapsed dialog

     void OnExpandButton() ;                         // call this in the handler of the                                                  // "More"/"Less" button
};


#endif /* _INC_EXPANDDLG_H_ */



//cpp file
// Expanding and collapsing dialogs
//
// Michael Walz (walz@epsitec.ch)
// Dec. 99
//

#include "stdafx.h"
#include "DialogExpander.h"


void ShrinkDialog(CWnd *pDlg, int idmark)
{  
     ASSERT(pDlg != NULL) ;  
     CWnd *pWndMark = pDlg->GetDlgItem(idmark) ;
     ASSERT(pWndMark != NULL) ;
     CRect markrect ;
     CRect dlgrect ;
     CRect clientrect ;
     CWnd *pParentWnd = pDlg->GetParent() ;
     int offset ;

     pDlg->GetClientRect(&clientrect) ;  // clientrect of the dialog
     pDlg->GetWindowRect(&dlgrect) ;       // rectangle of the dialog window

     // get height of the title bar
     offset = dlgrect.Height() - clientrect.bottom ;

     pWndMark->GetWindowRect(&markrect) ;


     pDlg->ScreenToClient(&markrect) ;

     // calculate the new rectangle of the dialog window
     dlgrect.bottom = dlgrect.top + markrect.bottom + offset;

     pDlg->MoveWindow (dlgrect.left, dlgrect.top, dlgrect.Width(), dlgrect.Height()) ;
}


CExpandDialog::CExpandDialog()
{
     m_sTextLess = "Less <<";
     m_bIsInitialized = FALSE ;
}


void CExpandDialog::Initialize(CWnd *pDialog, BOOL bInitiallyExpanded,
                                int IdExpandButton, int IdCollapsedMark)
{
     m_IdExpandButton = IdExpandButton;
     m_IdCollapsedMark = IdCollapsedMark;
     m_bIsInitialized = TRUE ;
     m_pDialog = pDialog ;
     m_bIsExpanded = TRUE ;

     m_pDialog->GetWindowRect(&m_dialogrect) ;       // rectangle of the dialog window
     m_pDialog->GetDlgItemText(IdExpandButton, m_sTextMore) ;

     if (bInitiallyExpanded)
     {
          CWnd *pButton = m_pDialog->GetDlgItem(m_IdExpandButton) ;
          pButton->SetWindowText(m_sTextLess ) ;
     }
     else
          OnExpandButton() ;
}


void CExpandDialog::OnExpandButton()
{
     ASSERT(m_bIsInitialized) ;

     CWnd *pButton ;
     m_bIsExpanded = !m_bIsExpanded ;    

     if (m_bIsExpanded)
     {
          // ShrinkDialog(m_pDialog, m_IdExpandedMark) ;
          CRect rect ;
          m_pDialog->GetWindowRect(&rect) ;
          rect.bottom = rect.top + m_dialogrect.Height() ;
          rect.right = rect.left + m_dialogrect.Width() ;
          m_pDialog->MoveWindow (&rect) ;
     }
     else
          ShrinkDialog(m_pDialog, m_IdCollapsedMark ) ;


     pButton = m_pDialog->GetDlgItem(m_IdExpandButton) ;
     pButton->SetWindowText(!m_bIsExpanded ? m_sTextMore : m_sTextLess ) ;
}




now, the implementation of your "Advance" button:
void CMyDialog::OnAdvance()
{
     m_ExpandDialog.OnExpandButton() ;
}

IDC_SHRINKMARK is a dummy control which marks the position of the collapse

cheers
0
 

Author Comment

by:web37
Comment Utility
sedgwick: how do i fix the control on my dialog?
i mean that do i need to make another resource dialog or put them all together?
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 250 total points
Comment Utility
u add all the controls in your dialog and a dummy control where u wanna expand and collapse the dialog.

btw, i forgot to mention that u need to call Initialize of the CExpandDialog in your OnInitDialog.

good luck
0
 
LVL 32

Expert Comment

by:jhance
Comment Utility
Since my tiny little comment got lost in these pages and pages of source codes:

Here's a complete example:

http://www.vckbase.com/english/code/dialog/expanding_dialog.shtml.htm
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:web37
Comment Utility
thank u all for your help.
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
sedgwick,
I am watching you.  If you continue answering your own questions to false aliases, you will be banned forever from EE.

-- Dan
0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
DanRollins: what makes u think that?
0
 
LVL 32

Expert Comment

by:jhance
Comment Utility
>>I am watching you.  If you continue answering your own questions to false aliases, you will be banned

That's a serious accusation.  

DanRollins, if you think there is funny business going on here why don't you report it to the EE moderators?
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
I already have.  The evidence was overwhelming.  Most of his aliases have been retired.  For fun, jhance, check through a bunch of his answered questions.  It can be quite entertaining.  Lots of new guys asking questions that are really stupid, then sedgwick posting a pre-written answer or saying "i emailed you the answer."  Then the alias saying "u da man!" and "that's the best answer I ever seen!" and such like.  Then watch him milk an alias.... as soon as the alias gets 50 points, he posts a new question for sedgwick to answer.  Pay attention to the timing of questions and answers.  Just long enough to log off and log back on with a new name.  Nauseating.

see http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20091739

and read the text that Tech_Ed posted to the questions listed there.

It bothers me when I spend time on a question and the points have been pre-allocated (it should bother you too, jhance).

-- Dan
0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
DanRollins: EE gave me a warning few months ago and i gave them all the false aliases, since then i neither created nor used a false alias.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ffmpeg - "rtsp://...... Operation not permitted" 4 65
bigDiff challenge 17 74
ShiftLeft challenge 21 65
Problem to event 3 47
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now