⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bcgworkspace.cpp

📁 一个完整的编辑器的代码(很值得参考
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	CBCGRegistry reg (FALSE, FALSE);
	return reg.DeleteKey(strSection);
}
//*************************************************************************************
BOOL CBCGWorkspace::SaveState (LPCTSTR lpszSectionName  /*=NULL*/, CBCGFrameImpl* pFrameImpl /*= NULL*/)
{
	if (lpszSectionName != NULL)
	{
		m_strRegSection = lpszSectionName;
	}

	CString strSection = GetRegSectionPath ();

	//-----------------------------
	// Other things to do before ?:
	//-----------------------------
	PreSaveState();

	//--------------------------------------
	// Save general toolbar/menu parameters:
	//--------------------------------------
	CBCGToolBar::SaveParameters (strSection);

	if (pFrameImpl != NULL) 
	{
		CDockState dockState;
		
		pFrameImpl->m_pFrame->GetDockState (dockState);
		dockState.SaveState (m_strRegSection + strRegEntryNameControlBars);

		//-----------------------------------------------------
		// Save all toolbars, menubar and docking control bars:
		//-----------------------------------------------------
		for (POSITION posTlb = gAllToolbars.GetHeadPosition (); posTlb != NULL;)
		{
			CBCGToolBar* pToolBar = (CBCGToolBar*) gAllToolbars.GetNext (posTlb);
			ASSERT (pToolBar != NULL);

			if (CWnd::FromHandlePermanent (pToolBar->m_hWnd) != NULL)
			{
				ASSERT_VALID(pToolBar);

				if (!pToolBar->m_bLocked && 
					!pFrameImpl->IsUserDefinedToolbar (pToolBar))
				{
					pToolBar->SaveState (strSection);
				}
			}
		}

		for (POSITION posCb = gAllSizingControlBars.GetHeadPosition (); posCb != NULL;)
		{
			CBCGSizingControlBar* pBar = (CBCGSizingControlBar*) gAllSizingControlBars.GetNext (posCb);
			ASSERT (pBar != NULL);

			if (CWnd::FromHandlePermanent (pBar->m_hWnd) != NULL)
			{
				ASSERT_VALID (pBar);
				pBar->SaveState (m_strRegSection + strRegEntryNameSizingBars);
			}
		}

		//----------------------------
		// Save user defined toolbars:
		//----------------------------
		pFrameImpl->SaveUserToolbars ();

		//-------------------
		// Save rebars state:
		//-------------------
		CBCGRebarState::SaveState (strSection, pFrameImpl->m_pFrame);
	}

	//------------------
	// Save user images:
	//------------------
	if (CBCGToolBar::m_pUserImages != NULL)
	{
		ASSERT_VALID (CBCGToolBar::m_pUserImages);
		CBCGToolBar::m_pUserImages->Save ();
	}

	//--------------------------------------
	// Save mouse/keyboard/menu managers:
	//--------------------------------------
	if (g_pMouseManager != NULL)
	{
		g_pMouseManager->SaveState (strSection);
	}

	if (g_pContextMenuManager != NULL)
	{
		g_pContextMenuManager->SaveState (strSection);
	}

	if (g_pKeyboardManager != NULL)
	{
		g_pKeyboardManager->SaveState (strSection,
			pFrameImpl == NULL ? NULL : pFrameImpl->m_pFrame);
	}

	SaveCustomState();
	return TRUE;
}

//*************************************************************************************
// Overidables for customization

void CBCGWorkspace::OnClosingMainFrame (CBCGFrameImpl* pFrame)
{
	// Defaults to automatically saving state.
	SaveState(0, pFrame);
}

//--------------------------------------------------------
// the next one have to be called explicitly in your code:
//--------------------------------------------------------
BOOL CBCGWorkspace::OnViewDoubleClick (CWnd* pWnd, int iViewId)
{
	if (g_pMouseManager == NULL)
	{
		ASSERT (FALSE);
		return FALSE;
	}

	ASSERT_VALID (g_pMouseManager);

	UINT uiCmd = g_pMouseManager->GetViewDblClickCommand (iViewId);
	if (uiCmd > 0 && uiCmd != (UINT) -1)
	{
		CWnd* pTargetWnd = (pWnd == NULL) ? 
			AfxGetMainWnd () : 
			pWnd->GetTopLevelFrame ();
		ASSERT_VALID (pTargetWnd);

		pTargetWnd->SendMessage (WM_COMMAND, uiCmd);
		return TRUE;
	}

	MessageBeep ((UINT) -1);
	return FALSE;
}
//***********************************************************************************
BOOL CBCGWorkspace::ShowPopupMenu (UINT uiMenuResId, const CPoint& point, CWnd* pWnd)
{
	if (g_pContextMenuManager == NULL)
	{
		ASSERT (FALSE);
		return FALSE;
	}

	ASSERT_VALID (g_pContextMenuManager);
	return g_pContextMenuManager->ShowPopupMenu (uiMenuResId,
				point.x, point.y, pWnd);
}
//***********************************************************************************
BOOL CBCGWorkspace::LoadWindowPlacement (
					CRect& rectNormalPosition, int& nFlags, int& nShowCmd)
{
	CBCGRegistry reg (FALSE, TRUE);
	if (!reg.Open (GetRegSectionPath (strWindowPlacementRegSection)))
	{
		return FALSE;
	}

	return	reg.Read (strRectMainKey, rectNormalPosition) &&
			reg.Read (strFlagsKey, nFlags) &&
			reg.Read (strShowCmdKey, nShowCmd);
}
//***********************************************************************************
BOOL CBCGWorkspace::StoreWindowPlacement (
					const CRect& rectNormalPosition, int nFlags, int nShowCmd)
{
	CBCGRegistry reg (FALSE, FALSE);
	if (!reg.CreateKey (GetRegSectionPath (strWindowPlacementRegSection)))
	{
		return FALSE;
	}

	return	reg.Write (strRectMainKey, rectNormalPosition) &&
			reg.Write (strFlagsKey, nFlags) &&
			reg.Write (strShowCmdKey, nShowCmd);
}
//*************************************************************************************
//*************************************************************************************
// These functions load and store values from the "Custom" subkey
// To use subkeys of the "Custom" subkey use GetSectionInt() etc.
// instead
int CBCGWorkspace::GetInt(LPCTSTR lpszEntry, int nDefault /*= 0*/)
{
	return GetSectionInt(_T(""), lpszEntry, nDefault);
}
//*************************************************************************************
CString	CBCGWorkspace::GetString(LPCTSTR lpszEntry, LPCTSTR lpszDefault /*= ""*/)
{
	return GetSectionString(_T(""), lpszEntry, lpszDefault);
}
//*************************************************************************************
BOOL CBCGWorkspace::GetBinary(LPCTSTR lpszEntry, LPBYTE* ppData, UINT* pBytes)
{
	return GetSectionBinary(_T(""), lpszEntry, ppData, pBytes);
}
//*************************************************************************************
BOOL CBCGWorkspace::GetObject(LPCTSTR lpszEntry, CObject& obj)
{
	return GetSectionObject(_T(""), lpszEntry, obj);
}
//*************************************************************************************
BOOL CBCGWorkspace::WriteInt(LPCTSTR lpszEntry, int nValue )
{
	return WriteSectionInt(_T(""), lpszEntry, nValue);
}
//*************************************************************************************
BOOL CBCGWorkspace::WriteString(LPCTSTR lpszEntry, LPCTSTR lpszValue )
{
	return WriteSectionString(_T(""), lpszEntry, lpszValue);
}
//*************************************************************************************
BOOL CBCGWorkspace::WriteBinary(LPCTSTR lpszEntry, LPBYTE pData, UINT nBytes)
{
	return WriteSectionBinary(_T(""), lpszEntry, pData, nBytes);
}
//*************************************************************************************
BOOL CBCGWorkspace::WriteObject(LPCTSTR lpszEntry, CObject& obj)
{
	return WriteSectionObject(_T(""), lpszEntry, obj);
}
//*************************************************************************************
//*************************************************************************************
// These functions load and store values from a given subkey
// of the "Custom" subkey. For simpler access you may use
// GetInt() etc.
int CBCGWorkspace::GetSectionInt( LPCTSTR lpszSubSection, LPCTSTR lpszEntry, int nDefault /*= 0*/)
{
	ASSERT(lpszSubSection);
	ASSERT(lpszEntry);
	
	int nRet = nDefault;

	CString strSection = GetRegSectionPath(lpszSubSection);

	CBCGRegistry reg (FALSE, TRUE);
	if (reg.Open (strSection))
	{
		reg.Read (lpszEntry, nRet);
	}
	return nRet;
}
//*************************************************************************************
CString CBCGWorkspace::GetSectionString( LPCTSTR lpszSubSection, LPCTSTR lpszEntry, LPCTSTR lpszDefault /*= ""*/)
{
	ASSERT(lpszSubSection);
	ASSERT(lpszEntry);
	ASSERT(lpszDefault);
	
	CString strRet = lpszDefault;

	CString strSection = GetRegSectionPath(lpszSubSection);

	CBCGRegistry reg (FALSE, TRUE);
	if (reg.Open (strSection))
	{
		reg.Read (lpszEntry, strRet);
	}
	return strRet;
}
//*************************************************************************************
BOOL CBCGWorkspace::GetSectionBinary(LPCTSTR lpszSubSection, LPCTSTR lpszEntry, LPBYTE* ppData, UINT* pBytes)
{
	ASSERT(lpszSubSection);
	ASSERT(lpszEntry);
	ASSERT(ppData);
	
	CString strSection = GetRegSectionPath(lpszSubSection);

	CBCGRegistry reg (FALSE, TRUE);
	if (reg.Open (strSection) 
		&& reg.Read (lpszEntry, ppData, pBytes) ) 
	{
		return TRUE;
	}
	return FALSE;
}
//*************************************************************************************
BOOL CBCGWorkspace::GetSectionObject(LPCTSTR lpszSubSection, LPCTSTR lpszEntry, CObject& obj)
{
	ASSERT(lpszSubSection);
	ASSERT(lpszEntry);
	ASSERT_VALID(&obj);
	
	CString strSection = GetRegSectionPath(lpszSubSection);

	CBCGRegistry reg (FALSE, TRUE);
	if (reg.Open (strSection) 
		&& reg.Read (lpszEntry, obj) ) 
	{
		return TRUE;
	}
	return FALSE;
}
//*************************************************************************************
BOOL CBCGWorkspace::WriteSectionInt( LPCTSTR lpszSubSection, LPCTSTR lpszEntry, int nValue )
{
	ASSERT(lpszSubSection);
	ASSERT(lpszEntry);
	
	CString strSection = GetRegSectionPath(lpszSubSection);

	CBCGRegistry reg (FALSE, FALSE);
	if (reg.CreateKey (strSection))
	{
		return reg.Write (lpszEntry, nValue);
	}
	return FALSE;
}
//*************************************************************************************
BOOL CBCGWorkspace::WriteSectionString( LPCTSTR lpszSubSection, LPCTSTR lpszEntry, LPCTSTR lpszValue )
{
	ASSERT(lpszSubSection);
	ASSERT(lpszEntry);
	ASSERT(lpszValue);

	CString strSection = GetRegSectionPath(lpszSubSection);

	CBCGRegistry reg (FALSE, FALSE);
	if (reg.CreateKey (strSection))
	{
		return reg.Write (lpszEntry, lpszValue);
	}
	return FALSE;
}
//*************************************************************************************
BOOL CBCGWorkspace::WriteSectionBinary(LPCTSTR lpszSubSection, LPCTSTR lpszEntry, LPBYTE pData, UINT nBytes)
{
	ASSERT(lpszSubSection);
	ASSERT(lpszEntry);
	ASSERT(pData);

	CString strSection = GetRegSectionPath(lpszSubSection);

	CBCGRegistry reg (FALSE, FALSE);
	if (reg.CreateKey (strSection))
	{
		return reg.Write (lpszEntry, pData, nBytes);
	}
	return FALSE;
}
//*************************************************************************************
BOOL CBCGWorkspace::WriteSectionObject(LPCTSTR lpszSubSection, LPCTSTR lpszEntry, CObject& obj)
{
	ASSERT(lpszSubSection);
	ASSERT(lpszEntry);
	ASSERT_VALID(&obj);

	CString strSection = GetRegSectionPath(lpszSubSection);

	CBCGRegistry reg (FALSE, FALSE);
	if (reg.CreateKey (strSection))
	{
		return reg.Write (lpszEntry, obj);
	}
	return FALSE;
}
//*************************************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -