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 CResizableDialog::CResizableDialog()
36 CResizableDialog::CResizableDialog(UINT nIDTemplate
, CWnd
* pParentWnd
)
37 : CDialog(nIDTemplate
, pParentWnd
)
41 CResizableDialog::CResizableDialog(LPCTSTR lpszTemplateName
, CWnd
* pParentWnd
)
42 : CDialog(lpszTemplateName
, pParentWnd
)
46 CResizableDialog::~CResizableDialog()
51 BEGIN_MESSAGE_MAP(CResizableDialog
, CDialog
)
52 //{{AFX_MSG_MAP(CResizableDialog)
61 /////////////////////////////////////////////////////////////////////////////
62 // CResizableDialog message handlers
64 BOOL
CResizableDialog::OnNcCreate(LPCREATESTRUCT lpCreateStruct
)
66 if (!CDialog::OnNcCreate(lpCreateStruct
))
69 // child dialogs don't want resizable border or size grip,
70 // nor they can handle the min/max size constraints
71 BOOL bChild
= lpCreateStruct
->style
& WS_CHILD
;
73 // create and init the size-grip
74 if (!CreateSizeGrip(!bChild
))
79 // set the initial size as the min track size
80 SetMinTrackSize(CSize(lpCreateStruct
->cx
, lpCreateStruct
->cy
));
83 MakeResizable(lpCreateStruct
);
88 void CResizableDialog::OnDestroy()
90 if (m_bEnableSaveRestore
)
91 SaveWindowRect(m_sSection
, m_bRectOnly
);
93 // remove child windows
99 void CResizableDialog::OnSize(UINT nType
, int cx
, int cy
)
101 CWnd::OnSize(nType
, cx
, cy
);
103 if (nType
== SIZE_MAXHIDE
|| nType
== SIZE_MAXSHOW
)
104 return; // arrangement not needed
106 if (nType
== SIZE_MAXIMIZED
)
107 HideSizeGrip(&m_dwGripTempState
);
109 ShowSizeGrip(&m_dwGripTempState
);
111 // update grip and layout
114 // on Vista, the redrawing doesn't work right, so we have to work
115 // around this by invalidating the whole dialog so the DWM recognizes
116 // that it has to update the application window.
120 void CResizableDialog::OnGetMinMaxInfo(MINMAXINFO FAR
* lpMMI
)
125 // NOTE: this must be called after setting the layout
126 // to have the dialog and its controls displayed properly
127 void CResizableDialog::EnableSaveRestore(LPCTSTR pszSection
, BOOL bRectOnly
, BOOL bHorzResize
, BOOL bVertResize
)
129 m_sSection
= pszSection
;
131 m_bEnableSaveRestore
= TRUE
;
132 m_bRectOnly
= bRectOnly
;
134 // restore immediately
135 LoadWindowRect(pszSection
, bRectOnly
, bHorzResize
, bVertResize
);
137 CMenu
* pMenu
= GetMenu();
142 BOOL
CResizableDialog::OnEraseBkgnd(CDC
* pDC
)
144 ClipChildren(pDC
, FALSE
);
146 BOOL bRet
= CDialog::OnEraseBkgnd(pDC
);
148 ClipChildren(pDC
, TRUE
);
153 LRESULT
CResizableDialog::WindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
155 if (message
!= WM_NCCALCSIZE
|| wParam
== 0 || m_noNcCalcSizeAdjustments
)
156 return CDialog::WindowProc(message
, wParam
, lParam
);
159 HandleNcCalcSize(FALSE
, (LPNCCALCSIZE_PARAMS
)lParam
, lResult
);
160 lResult
= CDialog::WindowProc(message
, wParam
, lParam
);
161 HandleNcCalcSize(TRUE
, (LPNCCALCSIZE_PARAMS
)lParam
, lResult
);
165 BOOL
CResizableDialog::AddOthersToAnchor()
167 CWnd
* pWnd
= GetWindow(GW_CHILD
);
170 if(!IsInAnchorList(pWnd
->m_hWnd
) && pWnd
->m_hWnd
!= m_wndGrip
.m_hWnd
)
171 this->AddAnchor(pWnd
->m_hWnd
,TOP_LEFT
);
173 pWnd
=pWnd
->GetNextWindow(GW_HWNDNEXT
);