1 // ResizableDialog.cpp : implementation file
3 /////////////////////////////////////////////////////////////////////////////
5 // Copyright (C) 2000-2002 by Paolo Messina
6 // (http://www.geocities.com/ppescher - ppescher@yahoo.com)
8 // The contents of this file are subject to the Artistic License (the "License").
9 // You may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at:
11 // http://www.opensource.org/licenses/artistic-license.html
13 // If you find this code useful, credits would be nice!
15 /////////////////////////////////////////////////////////////////////////////
18 #include "ResizableDialog.h"
23 static char THIS_FILE
[] = __FILE__
;
26 /////////////////////////////////////////////////////////////////////////////
29 inline void CResizableDialog::PrivateConstruct()
31 m_bEnableSaveRestore
= FALSE
;
32 m_dwGripTempState
= 1;
35 CResizableDialog::CResizableDialog()
40 CResizableDialog::CResizableDialog(UINT nIDTemplate
, CWnd
* pParentWnd
)
41 : CCmdUIDialog(nIDTemplate
, pParentWnd
)
46 CResizableDialog::CResizableDialog(LPCTSTR lpszTemplateName
, CWnd
* pParentWnd
)
47 : CCmdUIDialog(lpszTemplateName
, pParentWnd
)
52 CResizableDialog::~CResizableDialog()
57 BEGIN_MESSAGE_MAP(CResizableDialog
, CCmdUIDialog
)
58 //{{AFX_MSG_MAP(CResizableDialog)
68 /////////////////////////////////////////////////////////////////////////////
69 // CResizableDialog message handlers
71 int CResizableDialog::OnCreate(LPCREATESTRUCT lpCreateStruct
)
73 if (__super::OnCreate(lpCreateStruct
) == -1)
76 // child dialogs don't want resizable border or size grip,
77 // nor they can handle the min/max size constraints
78 BOOL bChild
= GetStyle() & WS_CHILD
;
85 // set resizable style
86 ModifyStyle(DS_MODALFRAME
, WS_POPUP
| WS_THICKFRAME
);
87 // adjust size to reflect new style
88 ::AdjustWindowRectEx(&rect
, GetStyle(),
89 ::IsMenu(GetMenu()->GetSafeHmenu()), GetExStyle());
90 SetWindowPos(NULL
, 0, 0, rect
.Width(), rect
.Height(), SWP_FRAMECHANGED
|
91 SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_NOREPOSITION
);
93 // set the initial size as the min track size
94 SetMinTrackSize(rect
.Size());
97 // create and init the size-grip
98 if (!CreateSizeGrip(!bChild
))
104 void CResizableDialog::OnDestroy()
106 if (m_bEnableSaveRestore
)
107 SaveWindowRect(m_sSection
, m_bRectOnly
);
109 // remove child windows
112 __super::OnDestroy();
115 void CResizableDialog::OnSize(UINT nType
, int cx
, int cy
)
117 CWnd::OnSize(nType
, cx
, cy
);
119 if (nType
== SIZE_MAXHIDE
|| nType
== SIZE_MAXSHOW
)
120 return; // arrangement not needed
122 if (nType
== SIZE_MAXIMIZED
)
123 HideSizeGrip(&m_dwGripTempState
);
125 ShowSizeGrip(&m_dwGripTempState
);
127 // update grip and layout
132 void CResizableDialog::OnGetMinMaxInfo(MINMAXINFO FAR
* lpMMI
)
137 // NOTE: this must be called after setting the layout
138 // to have the dialog and its controls displayed properly
139 void CResizableDialog::EnableSaveRestore(LPCTSTR pszSection
, BOOL bRectOnly
)
141 m_sSection
= pszSection
;
143 m_bEnableSaveRestore
= TRUE
;
144 m_bRectOnly
= bRectOnly
;
146 // restore immediately
147 LoadWindowRect(pszSection
, bRectOnly
);
151 BOOL
CResizableDialog::OnEraseBkgnd(CDC
* pDC
)
153 // Windows XP doesn't like clipping regions ...try this!
154 EraseBackground(pDC
);
157 /* ClipChildren(pDC); // old-method (for safety)
159 return CDialog::OnEraseBkgnd(pDC);