1 // ResizableDialog.cpp : implementation file
\r
3 /////////////////////////////////////////////////////////////////////////////
\r
5 // This file is part of ResizableLib
\r
6 // http://sourceforge.net/projects/resizablelib
\r
8 // Copyright (C) 2000-2004 by Paolo Messina
\r
9 // http://www.geocities.com/ppescher - mailto:ppescher@hotmail.com
\r
11 // The contents of this file are subject to the Artistic License (the "License").
\r
12 // You may not use this file except in compliance with the License.
\r
13 // You may obtain a copy of the License at:
\r
14 // http://www.opensource.org/licenses/artistic-license.html
\r
16 // If you find this code useful, credits would be nice!
\r
18 /////////////////////////////////////////////////////////////////////////////
\r
21 #include "ResizableDialog.h"
\r
24 #define new DEBUG_NEW
\r
26 static char THIS_FILE[] = __FILE__;
\r
29 /////////////////////////////////////////////////////////////////////////////
\r
32 inline void CResizableDialog::PrivateConstruct()
\r
34 m_bEnableSaveRestore = FALSE;
\r
35 m_dwGripTempState = 1;
\r
38 CResizableDialog::CResizableDialog()
\r
43 CResizableDialog::CResizableDialog(UINT nIDTemplate, CWnd* pParentWnd)
\r
44 : CDialog(nIDTemplate, pParentWnd)
\r
49 CResizableDialog::CResizableDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
\r
50 : CDialog(lpszTemplateName, pParentWnd)
\r
55 CResizableDialog::~CResizableDialog()
\r
60 BEGIN_MESSAGE_MAP(CResizableDialog, CDialog)
\r
61 //{{AFX_MSG_MAP(CResizableDialog)
\r
62 ON_WM_GETMINMAXINFO()
\r
70 /////////////////////////////////////////////////////////////////////////////
\r
71 // CResizableDialog message handlers
\r
73 BOOL CResizableDialog::OnNcCreate(LPCREATESTRUCT lpCreateStruct)
\r
75 if (!CDialog::OnNcCreate(lpCreateStruct))
\r
78 // child dialogs don't want resizable border or size grip,
\r
79 // nor they can handle the min/max size constraints
\r
80 BOOL bChild = lpCreateStruct->style & WS_CHILD;
\r
82 // create and init the size-grip
\r
83 if (!CreateSizeGrip(!bChild))
\r
88 // set the initial size as the min track size
\r
89 SetMinTrackSize(CSize(lpCreateStruct->cx, lpCreateStruct->cy));
\r
92 MakeResizable(lpCreateStruct);
\r
97 void CResizableDialog::OnDestroy()
\r
99 if (m_bEnableSaveRestore)
\r
100 SaveWindowRect(m_sSection, m_bRectOnly);
\r
102 // remove child windows
\r
103 RemoveAllAnchors();
\r
105 CDialog::OnDestroy();
\r
108 void CResizableDialog::OnSize(UINT nType, int cx, int cy)
\r
110 CWnd::OnSize(nType, cx, cy);
\r
112 if (nType == SIZE_MAXHIDE || nType == SIZE_MAXSHOW)
\r
113 return; // arrangement not needed
\r
115 if (nType == SIZE_MAXIMIZED)
\r
116 HideSizeGrip(&m_dwGripTempState);
\r
118 ShowSizeGrip(&m_dwGripTempState);
\r
120 // update grip and layout
\r
123 // on Vista, the redrawing doesn't work right, so we have to work
\r
124 // around this by invalidating the whole dialog so the DWM recognizes
\r
125 // that it has to update the application window.
\r
126 OSVERSIONINFOEX inf;
\r
127 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
\r
128 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
\r
129 GetVersionEx((OSVERSIONINFO *)&inf);
\r
130 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
\r
131 if (fullver >= 0x0600)
\r
135 void CResizableDialog::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
\r
140 // NOTE: this must be called after setting the layout
\r
141 // to have the dialog and its controls displayed properly
\r
142 void CResizableDialog::EnableSaveRestore(LPCTSTR pszSection, BOOL bRectOnly)
\r
144 m_sSection = pszSection;
\r
146 m_bEnableSaveRestore = TRUE;
\r
147 m_bRectOnly = bRectOnly;
\r
149 // restore immediately
\r
150 LoadWindowRect(pszSection, bRectOnly);
\r
152 CMenu* pMenu = GetMenu();
\r
157 BOOL CResizableDialog::OnEraseBkgnd(CDC* pDC)
\r
159 ClipChildren(pDC, FALSE);
\r
161 BOOL bRet = CDialog::OnEraseBkgnd(pDC);
\r
163 ClipChildren(pDC, TRUE);
\r
168 LRESULT CResizableDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
\r
170 if (message != WM_NCCALCSIZE || wParam == 0)
\r
171 return CDialog::WindowProc(message, wParam, lParam);
\r
173 LRESULT lResult = 0;
\r
174 HandleNcCalcSize(FALSE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
\r
175 lResult = CDialog::WindowProc(message, wParam, lParam);
\r
176 HandleNcCalcSize(TRUE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
\r