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

📄 profile.cpp

📁 A Model-View-Controller Framework that integrates with the MFC Doc/View architecture.
💻 CPP
字号:
#include "stdafx.h"
#include "Profile.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

   
namespace SbjCore
{
	namespace Sys
	{
	
		struct SetSharedProfileStateImpl
		{
			CWinApp* pApp;
			LPCTSTR lpszOldProfile;
			CString sShared;
			bool bSharable;
			
			SetSharedProfileStateImpl(bool bIsSharable) :
				pApp(::AfxGetApp()),
				bSharable(bIsSharable),
				lpszOldProfile(NULL)
			{
				if (pApp != NULL)
				{
					if (bSharable)
					{
						lpszOldProfile = pApp->m_pszProfileName;
						CString	sOldProfile(lpszOldProfile);
						sShared = _T("Shared\\") + sOldProfile;
						pApp->m_pszProfileName = sShared;
					}
				}
			}
			
			virtual ~SetSharedProfileStateImpl()
			{
				if (pApp != NULL)
				{
					if (bSharable)
					{
						pApp->m_pszProfileName = lpszOldProfile;
					}
				}
			}
		};

		SetSharedProfileState::SetSharedProfileState(bool bIsSharable) :
			m_pImpl(new SetSharedProfileStateImpl(bIsSharable))		
		{
		}

		SetSharedProfileState::~SetSharedProfileState()
		{
			try
			{
				delete m_pImpl;
			}
			catch (...)
			{
				ASSERT(FALSE);
			}
		}
	
		/////////////////////////////////////////////////////////////////////////////////////
		
		struct SetAlternateProfileImpl
		{
			CWinApp* pApp;
			LPCTSTR lpszOldProfile;
			CString sAltProfile;

			SetAlternateProfileImpl(LPCTSTR lpszAltProfile) :
				pApp(::AfxGetApp()),
				sAltProfile(lpszAltProfile == NULL ? _T("") : lpszAltProfile),
				lpszOldProfile(NULL)
			{
				if (!sAltProfile.IsEmpty())
				{
					if (pApp != NULL)
					{
						lpszOldProfile = pApp->m_pszProfileName;
						pApp->m_pszProfileName = sAltProfile;
					}
				}
			}

			virtual ~SetAlternateProfileImpl()
			{
				if (!sAltProfile.IsEmpty())
				{
					if (pApp != NULL)
					{
						pApp->m_pszProfileName = lpszOldProfile;
					}
				}
			}
		};

		SetAlternateProfile::SetAlternateProfile(LPCTSTR lpszAltProfile) :
			m_pImpl(new SetAlternateProfileImpl(lpszAltProfile))		
		{
		}

		SetAlternateProfile::~SetAlternateProfile()
		{
			try
			{
				delete m_pImpl;
			}
			catch (...)
			{
				ASSERT(FALSE);
			}
		}


		/////////////////////////////////////////////////////////////////////////////////////	
		
		const CString GetProfileValue(
			LPCTSTR lpszSection, 
			LPCTSTR lpszEntry, 
			LPCTSTR lpszValue,
			bool bCreateEntry /*= true*/,
			bool bIsShareable /*= false*/)
		{
			CString s;
			CWinApp* pApp = ::AfxGetApp();

			if (pApp != NULL)
			{
				SetSharedProfileState theState(bIsShareable);
				s = pApp->GetProfileString(lpszSection, lpszEntry, lpszValue);
				if (bCreateEntry)
				{
					pApp->WriteProfileString(lpszSection, lpszEntry, s);
				}
			}

			return s;
		}

		BOOL WriteProfileValue(
			LPCTSTR lpszSection, 
			LPCTSTR lpszEntry, 
			LPCTSTR lpszValue,
			bool bIsShareable /*= false*/)
		{
			bool bRslt = false;
			CWinApp* pApp = ::AfxGetApp();

			if (pApp != NULL)
			{
				SetSharedProfileState theState(bIsShareable);
				bRslt = pApp->WriteProfileString(lpszSection, lpszEntry, lpszValue);
			}

			return bRslt; 
		}

	}
}

⌨️ 快捷键说明

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