1 /////////////////////////////////////////////////////////////////////////////
\r
3 // This file is part of ResizableLib
\r
4 // http://sourceforge.net/projects/resizablelib
\r
6 // Copyright (C) 2000-2004,2008 by Paolo Messina
\r
7 // http://www.geocities.com/ppescher - mailto:ppescher@hotmail.com
\r
9 // The contents of this file are subject to the Artistic License (the "License").
\r
10 // You may not use this file except in compliance with the License.
\r
11 // You may obtain a copy of the License at:
\r
12 // http://www.opensource.org/licenses/artistic-license.html
\r
14 // If you find this code useful, credits would be nice!
\r
16 /////////////////////////////////////////////////////////////////////////////
\r
20 * @brief Implementation of the CResizableWndState class.
\r
24 #include "ResizableWndState.h"
\r
26 //////////////////////////////////////////////////////////////////////
\r
27 // Construction/Destruction
\r
28 //////////////////////////////////////////////////////////////////////
\r
30 CResizableWndState::CResizableWndState()
\r
35 CResizableWndState::~CResizableWndState()
\r
40 // used to save/restore window's size and position
\r
41 // either in the registry or a private .INI file
\r
42 // depending on your application settings
\r
44 #define PLACEMENT_ENT _T("WindowPlacement")
\r
45 #define PLACEMENT_FMT _T("%d,%d,%d,%d,%d,%d,%d,%d")
\r
48 * This function saves the current window position and size using the base
\r
49 * class persist method. Minimized and maximized state is also optionally
\r
51 * @sa CResizableState::WriteState
\r
52 * @note Window coordinates are in the form used by the system functions
\r
53 * GetWindowPlacement and SetWindowPlacement.
\r
55 * @param pszName String that identifies stored settings
\r
56 * @param bRectOnly Flag that specifies wether to ignore min/max state
\r
58 * @return Returns @a TRUE if successful, @a FALSE otherwise
\r
60 BOOL CResizableWndState::SaveWindowRect(LPCTSTR pszName, BOOL bRectOnly)
\r
65 SecureZeroMemory(&wp, sizeof(WINDOWPLACEMENT));
\r
66 wp.length = sizeof(WINDOWPLACEMENT);
\r
67 if (!GetResizableWnd()->GetWindowPlacement(&wp))
\r
70 // use workspace coordinates
\r
71 RECT& rc = wp.rcNormalPosition;
\r
73 if (bRectOnly) // save size/pos only (normal state)
\r
75 data.Format(PLACEMENT_FMT, rc.left, rc.top,
\r
76 rc.right, rc.bottom, SW_SHOWNORMAL, 0, 0, 0);
\r
78 else // save also min/max state
\r
80 data.Format(PLACEMENT_FMT, rc.left, rc.top,
\r
81 rc.right, rc.bottom, wp.showCmd, wp.flags,
\r
82 wp.ptMinPosition.x, wp.ptMinPosition.y);
\r
85 id = CString(pszName) + PLACEMENT_ENT;
\r
86 return WriteState(id, data);
\r
90 * This function loads and set the current window position and size using
\r
91 * the base class persist method. Minimized and maximized state is also
\r
92 * optionally preserved.
\r
93 * @sa CResizableState::WriteState
\r
94 * @note Window coordinates are in the form used by the system functions
\r
95 * GetWindowPlacement and SetWindowPlacement.
\r
97 * @param pszName String that identifies stored settings
\r
98 * @param bRectOnly Flag that specifies wether to ignore min/max state
\r
100 * @return Returns @a TRUE if successful, @a FALSE otherwise
\r
102 BOOL CResizableWndState::LoadWindowRect(LPCTSTR pszName, BOOL bRectOnly)
\r
105 WINDOWPLACEMENT wp;
\r
107 id = CString(pszName) + PLACEMENT_ENT;
\r
108 if (!ReadState(id, data)) // never saved before
\r
111 SecureZeroMemory(&wp, sizeof(WINDOWPLACEMENT));
\r
112 wp.length = sizeof(WINDOWPLACEMENT);
\r
113 if (!GetResizableWnd()->GetWindowPlacement(&wp))
\r
116 // use workspace coordinates
\r
117 RECT& rc = wp.rcNormalPosition;
\r
119 if (_stscanf(data, PLACEMENT_FMT, &rc.left, &rc.top,
\r
120 &rc.right, &rc.bottom, &wp.showCmd, &wp.flags,
\r
121 &wp.ptMinPosition.x, &wp.ptMinPosition.y) == 8)
\r
123 if (bRectOnly) // restore size/pos only
\r
125 wp.showCmd = SW_SHOWNORMAL;
\r
127 return GetResizableWnd()->SetWindowPlacement(&wp);
\r
129 else // restore also max state
\r
131 if (wp.showCmd == SW_SHOWMINIMIZED)
\r
132 wp.showCmd = SW_SHOWNORMAL;
\r
133 return GetResizableWnd()->SetWindowPlacement(&wp);
\r