00001
00002
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00016
00017 #include "stdafx.h"
00018 #include "ResizableState.h"
00019
00020 #ifdef _DEBUG
00021 #undef THIS_FILE
00022 static char THIS_FILE[]=__FILE__;
00023 #define new DEBUG_NEW
00024 #endif
00025
00027
00029
00030 CResizableState::CResizableState()
00031 {
00032
00033 }
00034
00035 CResizableState::~CResizableState()
00036 {
00037
00038 }
00039
00040
00041
00042
00043
00044
00045 #define PLACEMENT_ENT _T("WindowPlacement")
00046 #define PLACEMENT_FMT _T("%d,%d,%d,%d,%d,%d")
00047
00048 BOOL CResizableState::SaveWindowRect(LPCTSTR pszSection, BOOL bRectOnly)
00049 {
00050 CString data;
00051 WINDOWPLACEMENT wp;
00052
00053 ZeroMemory(&wp, sizeof(WINDOWPLACEMENT));
00054 wp.length = sizeof(WINDOWPLACEMENT);
00055 if (!GetResizableWnd()->GetWindowPlacement(&wp))
00056 return FALSE;
00057
00058 RECT& rc = wp.rcNormalPosition;
00059
00060 if (bRectOnly)
00061 {
00062
00063 GetResizableWnd()->GetWindowRect(&rc);
00064
00065 data.Format(PLACEMENT_FMT, rc.left, rc.top,
00066 rc.right, rc.bottom, SW_NORMAL, 0);
00067 }
00068 else
00069 {
00070
00071 data.Format(PLACEMENT_FMT, rc.left, rc.top,
00072 rc.right, rc.bottom, wp.showCmd, wp.flags);
00073 }
00074
00075 return AfxGetApp()->WriteProfileString(pszSection, PLACEMENT_ENT, data);
00076 }
00077
00078 BOOL CResizableState::LoadWindowRect(LPCTSTR pszSection, BOOL bRectOnly)
00079 {
00080 CString data;
00081 WINDOWPLACEMENT wp;
00082
00083 data = AfxGetApp()->GetProfileString(pszSection, PLACEMENT_ENT);
00084
00085 if (data.IsEmpty())
00086 return FALSE;
00087
00088 ZeroMemory(&wp, sizeof(WINDOWPLACEMENT));
00089 wp.length = sizeof(WINDOWPLACEMENT);
00090 if (!GetResizableWnd()->GetWindowPlacement(&wp))
00091 return FALSE;
00092
00093 RECT& rc = wp.rcNormalPosition;
00094
00095 if (_stscanf(data, PLACEMENT_FMT, &rc.left, &rc.top,
00096 &rc.right, &rc.bottom, &wp.showCmd, &wp.flags) == 6)
00097 {
00098 if (bRectOnly)
00099 {
00100 CRect rect(rc);
00101 return GetResizableWnd()->SetWindowPos(NULL, rect.left, rect.top,
00102 rect.Width(), rect.Height(), SWP_NOACTIVATE | SWP_NOZORDER |
00103 SWP_NOREPOSITION);
00104 }
00105 else
00106 {
00107 return GetResizableWnd()->SetWindowPlacement(&wp);
00108 }
00109 }
00110 return FALSE;
00111 }