Expanding Dialog

This article was contributed by D.Sivakumar

This article is based on an article contributed by Peter Pearson . Since I found my own version of this solution to be quite useful, in implementing expanding dialogs, I thought I would share mine with others as well. What I've done is to consolodate the code into a single function and provide a couple of bug fixes. Hopefully, this version will be of use to other people.

The single function is called ExpandyaContaract. Please note that I also changed the order in which the EnableWindow function is called. As per the original code, the static field also gets disabled. The other changes are the setting of the m_bExpanded flag to FALSE so that dialog starts with contracted mode and the calling of the ExpandyaContaract function from OnInitDialog.

// CExpandDlgDlg dialog 

class CExpandDlgDlg : public CDialog { 
// Construction 
 CExpandDlgDlg(CWnd* pParent = NULL); // standard constructor 

// Dialog Data
 CButton m_Devide; 

 // ClassWizard generated virtual function overrides
 virtual void DoDataExchange(CDataExchange* pDX);
 int m_nNormalWidth; 
 int m_nExpandedWidth; 
 BOOL m_bExpanded; 

// Implementation 
 HICON m_hIcon; 
 void ExpandyaContract(); 
 // Generated message map functions 
 virtual BOOL OnInitDialog(); 
 afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 
 afx_msg void OnPaint(); 
 afx_msg HCURSOR OnQueryDragIcon(); 
 afx_msg void OnButtonAdvanced(); 

void CExpandDlgDlg::OnButtonAdvanced() 
 // TODO: Add your control notification handler code here 

void CExpandDlgDlg::ExpandyaContract() 
 CRect rcDlg, rcMarker; 


 if (!m_bExpanded) 
  m_nExpandedWidth = rcDlg.Width(); 
  m_nNormalWidth = (rcMarker.right - rcDlg.left); 

  rcDlg.SetRect(rcDlg.left, rcDlg.top, rcDlg.left + m_nNormalWidth+12, 
  rcDlg.top + rcDlg.Height()); 

  HWND hWndChild = ::GetDlgItem(m_hWnd, IDC_STATIC_DEVIDE); 

  while (hWndChild != NULL) 
   hWndChild = ::GetNextWindow(hWndChild, GW_HWNDNEXT); 
   ::EnableWindow(hWndChild, m_bExpanded); 
  rcDlg.SetRect( rcDlg.left, rcDlg.top, rcDlg.left + + m_nExpandedWidth, 
  rcDlg.top + rcDlg.Height() ); 

  HWND hWndChild = ::GetDlgItem(m_hWnd, IDC_STATIC_DEVIDE); 

  while (hWndChild != NULL) 
   hWndChild = ::GetNextWindow(hWndChild, GW_HWNDNEXT); 
   ::EnableWindow(hWndChild, m_bExpanded); 

 MoveWindow(rcDlg, TRUE); 
 m_bExpanded = !m_bExpanded; 


Download source code - 11 Kb


  • Expand DialogBox

    Posted by Legacy on 07/24/2001 12:00am

    Originally posted by: Ed Liu

    What is the most simple way to do is changing the dialogbox's size by MoveWindow().

    • test

      Posted by hari on 11/08/2012 09:25pm

      this is test

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Enterprises are increasingly looking to platform as a service (PaaS) to lower their costs and speed their time to market for new applications. Developing, deploying, and managing applications in the cloud eliminates the time and expense of managing a physical infrastructure to support them. PaaS offerings must deliver additional long-term benefits, such as a lower total cost of ownership (TCO), rapid scalability, and ease of integration, all while providing robust security and availability. This report …

  • Anthony Christie, the Chief Marketing Officer for Level Communications, is responsible for customer experience, worldwide marketing and product management. In this informative asset, he shares his insights into why a private network connection to cloud-bases applications is the right decision for your enterprise. Download now to find out more.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date