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 
public: 
 CExpandDlgDlg(CWnd* pParent = NULL); // standard constructor 

// Dialog Data
 //{{AFX_DATA(CExpandDlgDlg) 
 enum { IDD = IDD_EXPANDDLG_DIALOG };
 CButton m_Devide; 
 //}}AFX_DATA 

 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CExpandDlgDlg)
protected: 
 virtual void DoDataExchange(CDataExchange* pDX);
 //}}AFX_VIRTUAL 
 int m_nNormalWidth; 
 int m_nExpandedWidth; 
 BOOL m_bExpanded; 

// Implementation 
protected: 
 HICON m_hIcon; 
 void ExpandyaContract(); 
 // Generated message map functions 
 //{{AFX_MSG(CExpandDlgDlg) 
 virtual BOOL OnInitDialog(); 
 afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 
 afx_msg void OnPaint(); 
 afx_msg HCURSOR OnQueryDragIcon(); 
 afx_msg void OnButtonAdvanced(); 
 //}}AFX_MSG 
 DECLARE_MESSAGE_MAP() 
}; 
  

void CExpandDlgDlg::OnButtonAdvanced() 
{ 
 // TODO: Add your control notification handler code here 
 ExpandyaContract(); 
} 

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

 GetWindowRect(rcDlg); 

 if (!m_bExpanded) 
 { 
  m_nExpandedWidth = rcDlg.Width(); 
  m_Devide.GetWindowRect(rcMarker); 
  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); 
  } 
 } 
 else 
 { 
  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; 
} 

Downloads

Download source code - 11 Kb


Comments

  • 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

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

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds