Update UNRAR.H
[xy_vsfilter.git] / src / ui / ResizableLib / ResizableState.cpp
blobbe7e05e4c99183cd4b5724c7bf602b1a8a2940d4
1 // ResizableState.cpp: implementation of the CResizableState class.
2 //
3 /////////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2000-2002 by Paolo Messina
6 // (http://www.geocities.com/ppescher - ppescher@yahoo.com)
7 //
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 /////////////////////////////////////////////////////////////////////////////
17 #include "stdafx.h"
18 #include "ResizableState.h"
20 #ifdef _DEBUG
21 #undef THIS_FILE
22 static char THIS_FILE[]=__FILE__;
23 #define new DEBUG_NEW
24 #endif
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)
50 CString data;
51 WINDOWPLACEMENT wp;
53 ZeroMemory(&wp, sizeof(WINDOWPLACEMENT));
54 wp.length = sizeof(WINDOWPLACEMENT);
55 if (!GetResizableWnd()->GetWindowPlacement(&wp))
56 return FALSE;
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)
80 CString data;
81 WINDOWPLACEMENT wp;
83 data = AfxGetApp()->GetProfileString(pszSection, PLACEMENT_ENT);
85 if (data.IsEmpty()) // never saved before
86 return FALSE;
88 ZeroMemory(&wp, sizeof(WINDOWPLACEMENT));
89 wp.length = sizeof(WINDOWPLACEMENT);
90 if (!GetResizableWnd()->GetWindowPlacement(&wp))
91 return FALSE;
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
100 CRect rect(rc);
101 return GetResizableWnd()->SetWindowPos(NULL, rect.left, rect.top,
102 rect.Width(), rect.Height(), SWP_NOACTIVATE | SWP_NOZORDER |
103 SWP_NOREPOSITION);
105 else // restore also min/max state
107 return GetResizableWnd()->SetWindowPlacement(&wp);
110 return FALSE;