1 // ResizableDialog.cpp : implementation file
3 /////////////////////////////////////////////////////////////////////////////
5 // This file is part of ResizableLib
6 // http://sourceforge.net/projects/resizablelib
8 // Copyright (C) 2000-2004 by Paolo Messina
9 // http://www.geocities.com/ppescher - mailto:ppescher@hotmail.com
11 // The contents of this file are subject to the Artistic License (the "License").
12 // You may not use this file except in compliance with the License.
13 // You may obtain a copy of the License at:
14 // http://www.opensource.org/licenses/artistic-license.html
16 // If you find this code useful, credits would be nice!
18 /////////////////////////////////////////////////////////////////////////////
21 #include "ResizableDialog.h"
26 static char THIS_FILE
[] = __FILE__
;
29 /////////////////////////////////////////////////////////////////////////////
32 inline void CResizableDialog::PrivateConstruct()
34 m_bEnableSaveRestore
= FALSE
;
35 m_dwGripTempState
= 1;
39 CResizableDialog::CResizableDialog()
44 CResizableDialog::CResizableDialog(UINT nIDTemplate
, CWnd
* pParentWnd
)
45 : CDialog(nIDTemplate
, pParentWnd
)
50 CResizableDialog::CResizableDialog(LPCTSTR lpszTemplateName
, CWnd
* pParentWnd
)
51 : CDialog(lpszTemplateName
, pParentWnd
)
56 CResizableDialog::~CResizableDialog()
61 BEGIN_MESSAGE_MAP(CResizableDialog
, CDialog
)
62 //{{AFX_MSG_MAP(CResizableDialog)
71 /////////////////////////////////////////////////////////////////////////////
72 // CResizableDialog message handlers
74 BOOL
CResizableDialog::OnNcCreate(LPCREATESTRUCT lpCreateStruct
)
76 if (!CDialog::OnNcCreate(lpCreateStruct
))
79 // child dialogs don't want resizable border or size grip,
80 // nor they can handle the min/max size constraints
81 BOOL bChild
= lpCreateStruct
->style
& WS_CHILD
;
83 // create and init the size-grip
84 if (!CreateSizeGrip(!bChild
))
89 // set the initial size as the min track size
90 SetMinTrackSize(CSize(lpCreateStruct
->cx
, lpCreateStruct
->cy
));
93 MakeResizable(lpCreateStruct
);
98 void CResizableDialog::OnDestroy()
100 if (m_bEnableSaveRestore
)
101 SaveWindowRect(m_sSection
, m_bRectOnly
);
103 // remove child windows
106 CDialog::OnDestroy();
109 void CResizableDialog::OnSize(UINT nType
, int cx
, int cy
)
111 CWnd::OnSize(nType
, cx
, cy
);
113 if (nType
== SIZE_MAXHIDE
|| nType
== SIZE_MAXSHOW
)
114 return; // arrangement not needed
116 if (nType
== SIZE_MAXIMIZED
)
117 HideSizeGrip(&m_dwGripTempState
);
119 ShowSizeGrip(&m_dwGripTempState
);
121 // update grip and layout
124 // on Vista, the redrawing doesn't work right, so we have to work
125 // around this by invalidating the whole dialog so the DWM recognizes
126 // that it has to update the application window.
130 void CResizableDialog::OnGetMinMaxInfo(MINMAXINFO FAR
* lpMMI
)
135 // NOTE: this must be called after setting the layout
136 // to have the dialog and its controls displayed properly
137 void CResizableDialog::EnableSaveRestore(LPCTSTR pszSection
, BOOL bRectOnly
, BOOL bHorzResize
, BOOL bVertResize
)
139 m_sSection
= pszSection
;
141 m_bEnableSaveRestore
= TRUE
;
142 m_bRectOnly
= bRectOnly
;
144 // restore immediately
145 LoadWindowRect(pszSection
, bRectOnly
, bHorzResize
, bVertResize
);
147 CMenu
* pMenu
= GetMenu();
152 BOOL
CResizableDialog::OnEraseBkgnd(CDC
* pDC
)
154 ClipChildren(pDC
, FALSE
);
156 BOOL bRet
= CDialog::OnEraseBkgnd(pDC
);
158 ClipChildren(pDC
, TRUE
);
163 LRESULT
CResizableDialog::WindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
165 if (message
!= WM_NCCALCSIZE
|| wParam
== 0)
166 return CDialog::WindowProc(message
, wParam
, lParam
);
169 HandleNcCalcSize(FALSE
, (LPNCCALCSIZE_PARAMS
)lParam
, lResult
);
170 lResult
= CDialog::WindowProc(message
, wParam
, lParam
);
171 HandleNcCalcSize(TRUE
, (LPNCCALCSIZE_PARAMS
)lParam
, lResult
);
175 BOOL
CResizableDialog::AddOthersToAnchor()
177 CWnd
* pWnd
= GetWindow(GW_CHILD
);
180 if(!IsInAnchorList(pWnd
->m_hWnd
) && pWnd
->m_hWnd
!= m_wndGrip
.m_hWnd
)
181 this->AddAnchor(pWnd
->m_hWnd
,TOP_LEFT
);
183 pWnd
=pWnd
->GetNextWindow(GW_HWNDNEXT
);