1 // ResizableState.cpp: implementation of the CResizableState class.
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 "ResizableState.h"
22 static char THIS_FILE
[]=__FILE__
;
26 //////////////////////////////////////////////////////////////////////
27 // Construction/Destruction
28 //////////////////////////////////////////////////////////////////////
30 CResizableState::CResizableState()
35 CResizableState::~CResizableState()
41 // used to save/restore window's size and position
42 // either in the registry or a private .INI file
43 // depending on your application settings
45 #define PLACEMENT_ENT _T("WindowPlacement")
46 #define PLACEMENT_FMT _T("%d,%d,%d,%d,%d,%d")
48 BOOL
CResizableState::SaveWindowRect(LPCTSTR pszSection
, BOOL bRectOnly
)
53 ZeroMemory(&wp
, sizeof(WINDOWPLACEMENT
));
54 wp
.length
= sizeof(WINDOWPLACEMENT
);
55 if (!GetResizableWnd()->GetWindowPlacement(&wp
))
58 RECT
& rc
= wp
.rcNormalPosition
; // alias
60 if (bRectOnly
) // save size/pos only (normal state)
62 // use screen coordinates
63 GetResizableWnd()->GetWindowRect(&rc
);
65 data
.Format(PLACEMENT_FMT
, rc
.left
, rc
.top
,
66 rc
.right
, rc
.bottom
, SW_NORMAL
, 0);
68 else // save also min/max state
70 // use workspace coordinates
71 data
.Format(PLACEMENT_FMT
, rc
.left
, rc
.top
,
72 rc
.right
, rc
.bottom
, wp
.showCmd
, wp
.flags
);
75 return AfxGetApp()->WriteProfileString(pszSection
, PLACEMENT_ENT
, data
);
78 BOOL
CResizableState::LoadWindowRect(LPCTSTR pszSection
, BOOL bRectOnly
)
83 data
= AfxGetApp()->GetProfileString(pszSection
, PLACEMENT_ENT
);
85 if (data
.IsEmpty()) // never saved before
88 ZeroMemory(&wp
, sizeof(WINDOWPLACEMENT
));
89 wp
.length
= sizeof(WINDOWPLACEMENT
);
90 if (!GetResizableWnd()->GetWindowPlacement(&wp
))
93 RECT
& rc
= wp
.rcNormalPosition
; // alias
95 if (_stscanf(data
, PLACEMENT_FMT
, &rc
.left
, &rc
.top
,
96 &rc
.right
, &rc
.bottom
, &wp
.showCmd
, &wp
.flags
) == 6)
98 if (bRectOnly
) // restore size/pos only
101 return GetResizableWnd()->SetWindowPos(NULL
, rect
.left
, rect
.top
,
102 rect
.Width(), rect
.Height(), SWP_NOACTIVATE
| SWP_NOZORDER
|
105 else // restore also min/max state
107 return GetResizableWnd()->SetWindowPlacement(&wp
);