-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathResizableWndState.cpp
135 lines (116 loc) · 3.89 KB
/
ResizableWndState.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/////////////////////////////////////////////////////////////////////////////
//
// This file is part of ResizableLib
// http://sourceforge.net/projects/resizablelib
//
// Copyright (C) 2000-2004 by Paolo Messina
// http://www.geocities.com/ppescher - mailto:[email protected]
//
// The contents of this file are subject to the Artistic License (the "License").
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// http://www.opensource.org/licenses/artistic-license.html
//
// If you find this code useful, credits would be nice!
//
/////////////////////////////////////////////////////////////////////////////
/*!
* @file
* @brief Implementation of the CResizableWndState class.
*/
#include "stdafx.h"
#include "ResizableWndState.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CResizableWndState::CResizableWndState()
{
}
CResizableWndState::~CResizableWndState()
{
}
// used to save/restore window's size and position
// either in the registry or a private .INI file
// depending on your application settings
#define PLACEMENT_ENT _T("WindowPlacement")
#define PLACEMENT_FMT _T("%d,%d,%d,%d,%d,%d,%d,%d")
/*!
* This function saves the current window position and size using the base
* class persist method. Minimized and maximized state is also optionally
* preserved.
* @sa CResizableState::WriteState
* @note Window coordinates are in the form used by the system functions
* GetWindowPlacement and SetWindowPlacement.
*
* @param pszName String that identifies stored settings
* @param bRectOnly Flag that specifies wether to ignore min/max state
*
* @return Returns @a TRUE if successful, @a FALSE otherwise
*/
BOOL CResizableWndState::SaveWindowRect(LPCTSTR pszName, BOOL bRectOnly)
{
CString data, id;
WINDOWPLACEMENT wp;
ZeroMemory(&wp, sizeof(WINDOWPLACEMENT));
wp.length = sizeof(WINDOWPLACEMENT);
if (!GetResizableWnd()->GetWindowPlacement(&wp))
return FALSE;
// use workspace coordinates
RECT& rc = wp.rcNormalPosition;
if (bRectOnly) // save size/pos only (normal state)
{
data.Format(PLACEMENT_FMT, rc.left, rc.top,
rc.right, rc.bottom, SW_SHOWNORMAL, 0, 0, 0);
}
else // save also min/max state
{
data.Format(PLACEMENT_FMT, rc.left, rc.top,
rc.right, rc.bottom, wp.showCmd, wp.flags,
wp.ptMinPosition.x, wp.ptMinPosition.y);
}
id = CString(pszName) + PLACEMENT_ENT;
return WriteState(id, data);
}
/*!
* This function loads and set the current window position and size using
* the base class persist method. Minimized and maximized state is also
* optionally preserved.
* @sa CResizableState::WriteState
* @note Window coordinates are in the form used by the system functions
* GetWindowPlacement and SetWindowPlacement.
*
* @param pszName String that identifies stored settings
* @param bRectOnly Flag that specifies wether to ignore min/max state
*
* @return Returns @a TRUE if successful, @a FALSE otherwise
*/
BOOL CResizableWndState::LoadWindowRect(LPCTSTR pszName, BOOL bRectOnly)
{
CString data, id;
WINDOWPLACEMENT wp;
id = CString(pszName) + PLACEMENT_ENT;
if (!ReadState(id, data)) // never saved before
return FALSE;
ZeroMemory(&wp, sizeof(WINDOWPLACEMENT));
wp.length = sizeof(WINDOWPLACEMENT);
if (!GetResizableWnd()->GetWindowPlacement(&wp))
return FALSE;
// use workspace coordinates
RECT& rc = wp.rcNormalPosition;
if (_stscanf(data, PLACEMENT_FMT, &rc.left, &rc.top,
&rc.right, &rc.bottom, &wp.showCmd, &wp.flags,
&wp.ptMinPosition.x, &wp.ptMinPosition.y) == 8)
{
if (bRectOnly) // restore size/pos only
{
wp.showCmd = SW_SHOWNORMAL;
wp.flags = 0;
return GetResizableWnd()->SetWindowPlacement(&wp);
}
else // restore also min/max state
{
return GetResizableWnd()->SetWindowPlacement(&wp);
}
}
return FALSE;
}