Solved

expand dialog

Posted on 2001-08-19
12
363 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 6403227
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
ID: 6403274
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 6403441
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:web37
ID: 6403450
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
ID: 6403690
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
ID: 6404485
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
 

Author Comment

by:web37
ID: 6405080
thank u all for your help.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6405193
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
ID: 6405784
DanRollins: what makes u think that?
0
 
LVL 32

Expert Comment

by:jhance
ID: 6405820
>>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
ID: 6405881
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
ID: 6405918
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sameEnds challenge 3 197
centeredAverage challenge 8 188
pre4 challenge 19 116
Adjust the codes 3 65
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

752 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