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;
38 CResizableDialog::CResizableDialog()
43 CResizableDialog::CResizableDialog(UINT nIDTemplate
, CWnd
* pParentWnd
)
44 : CDialog(nIDTemplate
, pParentWnd
)
49 CResizableDialog::CResizableDialog(LPCTSTR lpszTemplateName
, CWnd
* pParentWnd
)
50 : CDialog(lpszTemplateName
, pParentWnd
)
55 CResizableDialog::~CResizableDialog()
60 BEGIN_MESSAGE_MAP(CResizableDialog
, CDialog
)
61 //{{AFX_MSG_MAP(CResizableDialog)
70 /////////////////////////////////////////////////////////////////////////////
71 // CResizableDialog message handlers
73 BOOL
CResizableDialog::OnNcCreate(LPCREATESTRUCT lpCreateStruct
)
75 if (!CDialog::OnNcCreate(lpCreateStruct
))
78 // child dialogs don't want resizable border or size grip,
79 // nor they can handle the min/max size constraints
80 BOOL bChild
= lpCreateStruct
->style
& WS_CHILD
;
82 // create and init the size-grip
83 if (!CreateSizeGrip(!bChild
))
88 // set the initial size as the min track size
89 SetMinTrackSize(CSize(lpCreateStruct
->cx
, lpCreateStruct
->cy
));
92 MakeResizable(lpCreateStruct
);
97 void CResizableDialog::OnDestroy()
99 if (m_bEnableSaveRestore
)
100 SaveWindowRect(m_sSection
, m_bRectOnly
);
102 // remove child windows
105 CDialog::OnDestroy();
108 void CResizableDialog::OnSize(UINT nType
, int cx
, int cy
)
110 CWnd::OnSize(nType
, cx
, cy
);
112 if (nType
== SIZE_MAXHIDE
|| nType
== SIZE_MAXSHOW
)
113 return; // arrangement not needed
115 if (nType
== SIZE_MAXIMIZED
)
116 HideSizeGrip(&m_dwGripTempState
);
118 ShowSizeGrip(&m_dwGripTempState
);
120 // update grip and layout
123 // on Vista, the redrawing doesn't work right, so we have to work
124 // around this by invalidating the whole dialog so the DWM recognizes
125 // that it has to update the application window.
127 SecureZeroMemory(&inf
, sizeof(OSVERSIONINFOEX
));
128 inf
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
129 GetVersionEx((OSVERSIONINFO
*)&inf
);
130 WORD fullver
= MAKEWORD(inf
.dwMinorVersion
, inf
.dwMajorVersion
);
131 if (fullver
>= 0x0600)
135 void CResizableDialog::OnGetMinMaxInfo(MINMAXINFO FAR
* lpMMI
)
140 // NOTE: this must be called after setting the layout
141 // to have the dialog and its controls displayed properly
142 void CResizableDialog::EnableSaveRestore(LPCTSTR pszSection
, BOOL bRectOnly
)
144 m_sSection
= pszSection
;
146 m_bEnableSaveRestore
= TRUE
;
147 m_bRectOnly
= bRectOnly
;
149 // restore immediately
150 LoadWindowRect(pszSection
, bRectOnly
);
152 CMenu
* pMenu
= GetMenu();
157 BOOL
CResizableDialog::OnEraseBkgnd(CDC
* pDC
)
159 ClipChildren(pDC
, FALSE
);
161 BOOL bRet
= CDialog::OnEraseBkgnd(pDC
);
163 ClipChildren(pDC
, TRUE
);
168 LRESULT
CResizableDialog::WindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
170 if (message
!= WM_NCCALCSIZE
|| wParam
== 0)
171 return CDialog::WindowProc(message
, wParam
, lParam
);
174 HandleNcCalcSize(FALSE
, (LPNCCALCSIZE_PARAMS
)lParam
, lResult
);
175 lResult
= CDialog::WindowProc(message
, wParam
, lParam
);
176 HandleNcCalcSize(TRUE
, (LPNCCALCSIZE_PARAMS
)lParam
, lResult
);
180 BOOL
CResizableDialog::AddOthersToAnchor()
182 CWnd
* pWnd
= GetWindow(GW_CHILD
);
185 if(!IsInAnchorList(pWnd
->m_hWnd
) && pWnd
->m_hWnd
!= m_wndGrip
.m_hWnd
)
186 this->AddAnchor(pWnd
->m_hWnd
,TOP_LEFT
);
188 pWnd
=pWnd
->GetNextWindow(GW_HWNDNEXT
);