📄 dockstat.cpp
字号:
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.
#include "stdafx.h"
#ifdef AFX_CORE3_SEG
#pragma code_seg(AFX_CORE3_SEG)
#endif
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define new DEBUG_NEW
/////////////////////////////////////////////////////////////////////////////
// CDockState
AFX_STATIC_DATA const TCHAR _afxVisible[] = _T("Visible");
AFX_STATIC_DATA const TCHAR _afxBarSection[] = _T("%s-Bar%d");
AFX_STATIC_DATA const TCHAR _afxSummarySection[] = _T("%s-Summary");
AFX_STATIC_DATA const TCHAR _afxXPos[] = _T("XPos");
AFX_STATIC_DATA const TCHAR _afxYPos[] = _T("YPos");
AFX_STATIC_DATA const TCHAR _afxMRUWidth[] = _T("MRUWidth");
AFX_STATIC_DATA const TCHAR _afxDocking[] = _T("Docking");
AFX_STATIC_DATA const TCHAR _afxMRUDockID[] = _T("MRUDockID");
AFX_STATIC_DATA const TCHAR _afxMRUDockLeftPos[] = _T("MRUDockLeftPos");
AFX_STATIC_DATA const TCHAR _afxMRUDockRightPos[] = _T("MRUDockRightPos");
AFX_STATIC_DATA const TCHAR _afxMRUDockTopPos[] = _T("MRUDockTopPos");
AFX_STATIC_DATA const TCHAR _afxMRUDockBottomPos[] = _T("MRUDockBottomPos");
AFX_STATIC_DATA const TCHAR _afxMRUFloatStyle[] = _T("MRUFloatStyle");
AFX_STATIC_DATA const TCHAR _afxMRUFloatXPos[] = _T("MRUFloatXPos");
AFX_STATIC_DATA const TCHAR _afxMRUFloatYPos[] = _T("MRUFloatYPos");
AFX_STATIC_DATA const TCHAR _afxBarID[] = _T("BarID");
AFX_STATIC_DATA const TCHAR _afxHorz[] = _T("Horz");
AFX_STATIC_DATA const TCHAR _afxFloating[] = _T("Floating");
AFX_STATIC_DATA const TCHAR _afxBars[] = _T("Bars");
AFX_STATIC_DATA const TCHAR _afxScreenCX[] = _T("ScreenCX");
AFX_STATIC_DATA const TCHAR _afxScreenCY[] = _T("ScreenCY");
AFX_STATIC_DATA const TCHAR _afxBar[] = _T("Bar#%d");
CControlBarInfo::CControlBarInfo()
{
m_nBarID = 0;
m_bDockBar = m_bVisible = m_bFloating = m_bHorz = m_bDocking = FALSE;
m_pBar = NULL;
m_pointPos.x = m_pointPos.y = -1;
m_nMRUWidth = 32767;
m_uMRUDockID = 0;
m_rectMRUDockPos.SetRectEmpty();
m_dwMRUFloatStyle = 0;
m_ptMRUFloatPos = CPoint(0,0);
ASSERT(sizeof(DWORD) == sizeof(void*));
}
void CControlBarInfo::Serialize(CArchive& ar, CDockState* pDockState)
{
ASSERT(pDockState!=NULL);
if (ar.IsStoring())
{
ar << (DWORD)m_nBarID;
ar << (DWORD)m_bVisible;
ar << (DWORD)m_bFloating;
ar << (DWORD)m_bHorz;
ar << m_pointPos;
if (pDockState->GetVersion() > 1)
{
ar << (DWORD)m_nMRUWidth;
ar << (DWORD)m_bDocking;
if (m_bDocking)
{
ar << (DWORD)m_uMRUDockID;
ar << m_rectMRUDockPos;
ar << m_dwMRUFloatStyle;
ar << m_ptMRUFloatPos;
}
}
ar << (WORD)m_arrBarID.GetSize();
if (m_arrBarID.GetSize() != 0)
{
#ifdef _AFX_BYTESWAP
if (!ar.IsByteSwapping())
#endif
ar.Write(&m_arrBarID.ElementAt(0),
m_arrBarID.GetSize()*sizeof(DWORD));
#ifdef _AFX_BYTESWAP
else
{
// write each ID individually so that it will be byte-swapped
for (int i = 0; i < m_arrBarID.GetSize(); i++)
ar << (DWORD)m_arrBarID[i];
}
#endif
}
}
else
{
DWORD dw;
ar >> dw;
m_nBarID = (int)dw;
ar >> dw;
m_bVisible = (BOOL)dw;
ar >> dw;
m_bFloating = (BOOL)dw;
ar >> dw;
m_bHorz = (BOOL)dw;
ar >> m_pointPos;
if (pDockState->GetVersion() > 1)
{
pDockState->ScalePoint(m_pointPos);
ar >> dw;
m_nMRUWidth = (int)dw;
ar >> dw;
m_bDocking = (BOOL)dw;
if (m_bDocking)
{
ar >> dw;
m_uMRUDockID = (DWORD)dw;
ar >> m_rectMRUDockPos;
pDockState->ScaleRectPos(m_rectMRUDockPos);
ar >> m_dwMRUFloatStyle;
ar >> m_ptMRUFloatPos;
pDockState->ScalePoint(m_ptMRUFloatPos);
}
}
WORD w;
ar >> w;
m_arrBarID.SetSize(w);
if (w != 0)
{
ar.Read(&m_arrBarID.ElementAt(0),
m_arrBarID.GetSize()*sizeof(DWORD));
#ifdef _AFX_BYTESWAP
if (ar.IsByteSwapping())
{
for (int i = 0; i < m_arrBarID.GetSize(); i++)
_AfxByteSwap((DWORD)m_arrBarID[i], (BYTE*)&m_arrBarID[i]);
}
#endif
}
}
}
BOOL CControlBarInfo::LoadState(LPCTSTR lpszProfileName, int nIndex, CDockState* pDockState)
{
ASSERT(pDockState != NULL);
CWinApp* pApp = AfxGetApp();
TCHAR szSection[256];
wsprintf(szSection, _afxBarSection, lpszProfileName, nIndex);
m_nBarID = pApp->GetProfileInt(szSection, _afxBarID, 0);
m_bVisible = (BOOL) pApp->GetProfileInt(szSection, _afxVisible, TRUE);
m_bHorz = (BOOL) pApp->GetProfileInt(szSection, _afxHorz, TRUE);
m_bFloating = (BOOL) pApp->GetProfileInt(szSection, _afxFloating, FALSE);
m_pointPos = CPoint(
pApp->GetProfileInt(szSection, _afxXPos, -1),
pApp->GetProfileInt(szSection, _afxYPos, -1));
pDockState->ScalePoint(m_pointPos);
m_nMRUWidth = pApp->GetProfileInt(szSection, _afxMRUWidth, 32767);
m_bDocking = pApp->GetProfileInt(szSection, _afxDocking, 0);
if (m_bDocking)
{
m_uMRUDockID = pApp->GetProfileInt(szSection, _afxMRUDockID, 0);
m_rectMRUDockPos = CRect(
pApp->GetProfileInt(szSection, _afxMRUDockLeftPos, 0),
pApp->GetProfileInt(szSection, _afxMRUDockTopPos, 0),
pApp->GetProfileInt(szSection, _afxMRUDockRightPos, 0),
pApp->GetProfileInt(szSection, _afxMRUDockBottomPos, 0));
pDockState->ScaleRectPos(m_rectMRUDockPos);
m_dwMRUFloatStyle = pApp->GetProfileInt(szSection, _afxMRUFloatStyle, 0);
m_ptMRUFloatPos = CPoint(
pApp->GetProfileInt(szSection, _afxMRUFloatXPos, 0),
pApp->GetProfileInt(szSection, _afxMRUFloatYPos, 0));
pDockState->ScalePoint(m_ptMRUFloatPos);
}
int nBars = pApp->GetProfileInt(szSection, _afxBars, 0);
for (int i=0; i < nBars; i++)
{
TCHAR buf[16];
wsprintf(buf, _afxBar, i);
m_arrBarID.Add((void*)pApp->GetProfileInt(szSection, buf, 0));
}
return m_nBarID != 0;
}
BOOL CControlBarInfo::SaveState(LPCTSTR lpszProfileName, int nIndex)
{
TCHAR szSection[256];
wsprintf(szSection, _afxBarSection, lpszProfileName, nIndex);
// delete the section
CWinApp* pApp = AfxGetApp();
pApp->WriteProfileString(szSection, NULL, NULL);
if (m_bDockBar && m_bVisible && !m_bFloating && m_pointPos.x == -1 &&
m_pointPos.y == -1 && m_arrBarID.GetSize() <= 1)
{
return FALSE;
}
pApp->WriteProfileInt(szSection, _afxBarID, m_nBarID);
if (!m_bVisible)
pApp->WriteProfileInt(szSection, _afxVisible, m_bVisible);
if (m_bFloating)
{
pApp->WriteProfileInt(szSection, _afxHorz, m_bHorz);
pApp->WriteProfileInt(szSection, _afxFloating, m_bFloating);
}
if (m_pointPos.x != -1)
pApp->WriteProfileInt(szSection, _afxXPos, m_pointPos.x);
if (m_pointPos.y != -1)
pApp->WriteProfileInt(szSection, _afxYPos, m_pointPos.y);
if (m_nMRUWidth != 32767)
pApp->WriteProfileInt(szSection, _afxMRUWidth, m_nMRUWidth);
if (m_bDocking)
{
pApp->WriteProfileInt(szSection, _afxDocking, m_bDocking);
pApp->WriteProfileInt(szSection, _afxMRUDockID, m_uMRUDockID);
pApp->WriteProfileInt(szSection, _afxMRUDockLeftPos, m_rectMRUDockPos.left);
pApp->WriteProfileInt(szSection, _afxMRUDockTopPos, m_rectMRUDockPos.top);
pApp->WriteProfileInt(szSection, _afxMRUDockRightPos, m_rectMRUDockPos.right);
pApp->WriteProfileInt(szSection, _afxMRUDockBottomPos, m_rectMRUDockPos.bottom);
pApp->WriteProfileInt(szSection, _afxMRUFloatStyle, m_dwMRUFloatStyle);
pApp->WriteProfileInt(szSection, _afxMRUFloatXPos, m_ptMRUFloatPos.x);
pApp->WriteProfileInt(szSection, _afxMRUFloatYPos, m_ptMRUFloatPos.y);
}
if (m_arrBarID.GetSize() > 1) //if ==1 then still empty
{
pApp->WriteProfileInt(szSection, _afxBars, m_arrBarID.GetSize());
for (int i = 0; i < m_arrBarID.GetSize(); i++)
{
TCHAR buf[16];
wsprintf(buf, _afxBar, i);
pApp->WriteProfileInt(szSection, buf, (int)m_arrBarID[i]);
}
}
return TRUE;
}
CDockState::CDockState()
{
m_dwVersion = 2;
m_bScaling = FALSE;
m_rectDevice.left = 0;
m_rectDevice.top = 0;
m_rectDevice.right = GetSystemMetrics(SM_CXSCREEN);
m_rectDevice.bottom = GetSystemMetrics(SM_CYSCREEN);
m_rectClip = m_rectDevice;
m_rectClip.right -= GetSystemMetrics(SM_CXICON);
m_rectClip.bottom -= GetSystemMetrics(SM_CYICON);
}
CDockState::~CDockState()
{
for (int i = 0; i < m_arrBarInfo.GetSize(); i++)
delete (CControlBarInfo*)m_arrBarInfo[i];
}
void CDockState::Serialize(CArchive& ar)
{
// read/write version info
if (ar.IsStoring())
{
ar << m_dwVersion;
if (m_dwVersion > 1)
{
ar << GetScreenSize();
}
// write array contents
ar << (WORD)m_arrBarInfo.GetSize();
for (int i = 0; i < m_arrBarInfo.GetSize(); i++)
((CControlBarInfo*)m_arrBarInfo[i])->Serialize(ar, this);
}
else
{
Clear(); //empty out dockstate
ar >> m_dwVersion; // read version marker
ASSERT(m_dwVersion == 1 || m_dwVersion == 2);
if (m_dwVersion > 1)
{
CSize size;
ar >> size;
SetScreenSize(size);
}
// read array contents
WORD nOldSize;
ar >> nOldSize;
m_arrBarInfo.SetSize(nOldSize);
for (int i = 0; i < m_arrBarInfo.GetSize(); i++)
{
m_arrBarInfo[i] = new CControlBarInfo;
((CControlBarInfo*)m_arrBarInfo[i])->Serialize(ar, this);
}
m_dwVersion = 2;
}
}
void CDockState::LoadState(LPCTSTR lpszProfileName)
{
CWinApp* pApp = AfxGetApp();
TCHAR szSection[256];
wsprintf(szSection, _afxSummarySection, lpszProfileName);
int nBars = pApp->GetProfileInt(szSection, _afxBars, 0);
CSize size;
size.cx = pApp->GetProfileInt(szSection, _afxScreenCX, 0);
size.cy = pApp->GetProfileInt(szSection, _afxScreenCY, 0);
SetScreenSize(size);
for (int i = 0; i < nBars; i++)
{
CControlBarInfo* pInfo = new CControlBarInfo;
m_arrBarInfo.Add(pInfo);
pInfo->LoadState(lpszProfileName, i, this);
}
}
void CDockState::SaveState(LPCTSTR lpszProfileName)
{
int nIndex = 0;
for (int i = 0;i < m_arrBarInfo.GetSize(); i++)
{
CControlBarInfo* pInfo = (CControlBarInfo*)m_arrBarInfo[i];
ASSERT(pInfo != NULL);
if (pInfo->SaveState(lpszProfileName, nIndex))
nIndex++;
}
CWinApp* pApp = AfxGetApp();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -