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

📄 sstate.h

📁 These listed libraries are written in WTL. But it s really hard to mix both MFC & WTL together. Obvi
💻 H
📖 第 1 页 / 共 2 页
字号:
			general.SetBinary(ctxtCXScreen,&val,sizeof(DWORD));
			val=::GetSystemMetrics(SM_CYSCREEN);
			general.SetBinary(ctxtCYScreen,&val,sizeof(DWORD));
		}

		TStorage stg;
		bool bRes=(stg.Create(stgMain,ctxtMainWindow,IStorge::ReadWrite)==ERROR_SUCCESS);
		if(bRes)
			bRes=m_pImpl->Store(stg);

//         DWORD dwDisposition;
// 		CRegKey keyMain;
//         if(keyMain.Create(HKEY_CURRENT_USER,m_strMainKey.c_str(),REG_NONE,
//                                     REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ,
//                                     NULL,&dwDisposition)==ERROR_SUCCESS)
//         {
//             CRegKey keyGeneral;
//             if(keyGeneral.Create(keyMain,ctxtGeneral,REG_NONE,
// 										REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ,
// 										NULL,&dwDisposition)==ERROR_SUCCESS)
//             {
// 
// 				DWORD val=::GetSystemMetrics(SM_CXSCREEN);
// 				::RegSetValueEx(keyGeneral, ctxtCXScreen, NULL, REG_DWORD,
// 								reinterpret_cast<BYTE*>(&val), sizeof(DWORD));
// 				val=::GetSystemMetrics(SM_CYSCREEN);
// 				::RegSetValueEx(keyGeneral, ctxtCYScreen, NULL, REG_DWORD,
// 								reinterpret_cast<BYTE*>(&val), sizeof(DWORD));
// /*
// 				keyGeneral.SetValue(::GetSystemMetrics(SM_CXSCREEN),ctxtCXScreen);
// 				keyGeneral.SetValue(::GetSystemMetrics(SM_CYSCREEN),ctxtCYScreen);
// */
//             }
//             CRegKey key;
//             if(key.Create(keyMain,ctxtMainWindow,REG_NONE,
// 							REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ,
// 							NULL,&dwDisposition)==ERROR_SUCCESS)
// 									m_pImpl->Store(key);
//         }
		return bRes;
    }

    bool Restore(TStorage& stgMain)
    {
		TStorage general;
		bool bRes=(general.Open(stgMain,ctxtGeneral,IStorge::Read)==ERROR_SUCCESS);
		if(bRes)
		{
            SIZE szScreen;
			size_t size = sizeof(DWORD);
			float xratio=(general.GetBinary(ctxtCXScreen,&szScreen.cx,size)==ERROR_SUCCESS
							 && (size == sizeof(DWORD))
                                            ?float(::GetSystemMetrics(SM_CXSCREEN))/szScreen.cx
                                            :float(1.0));
				
			size = sizeof(DWORD);
			float yratio=(general.GetBinary(ctxtCYScreen,&szScreen.cy,size)==ERROR_SUCCESS
							&& (size == sizeof(DWORD))
                                            ?float(::GetSystemMetrics(SM_CYSCREEN))/szScreen.cy
                                            :float(1.0));

			TStorage stg;
			bRes=(stg.Open(stgMain,ctxtMainWindow,IStorge::Read)==ERROR_SUCCESS
							&& m_pImpl->Restore(stg,xratio,yratio));
		}

// 		CRegKey keyMain;
//         CRegKey keyGeneral;
// 		bool bRes=keyMain.Open(HKEY_CURRENT_USER,m_strMainKey.c_str(),KEY_READ)==ERROR_SUCCESS
// 									&& (keyGeneral.Open(keyMain,ctxtGeneral,KEY_READ)==ERROR_SUCCESS);
//         if(bRes)
//         {
//             SIZE szScreen;
// 			DWORD dwCount = sizeof(DWORD);
// 			float xratio=(::RegQueryValueEx(keyGeneral,ctxtCXScreen,NULL,NULL,
// 							reinterpret_cast<LPBYTE>(&szScreen.cx),&dwCount) ==ERROR_SUCCESS
// 								&& (dwCount == sizeof(DWORD)))
//                                             ?float(::GetSystemMetrics(SM_CXSCREEN))/szScreen.cx
//                                             :float(1.0);
// 			dwCount = sizeof(DWORD);
// 			float yratio=(::RegQueryValueEx(keyGeneral,ctxtCYScreen,NULL,NULL,
// 							reinterpret_cast<LPBYTE>(&szScreen.cy),&dwCount) ==ERROR_SUCCESS
// 								&&(dwCount == sizeof(DWORD)))
//                                             ?float(::GetSystemMetrics(SM_CYSCREEN))/szScreen.cy
//                                             :float(1.0);
// /*
//             xratio=(keyGeneral.QueryValue(reinterpret_cast<DWORD&>(szScreen.cx),ctxtCXScreen)==ERROR_SUCCESS)
//                                             ?float(::GetSystemMetrics(SM_CXSCREEN))/szScreen.cx
//                                             :float(1.0);
//             yratio=(keyGeneral.QueryValue(reinterpret_cast<DWORD&>(szScreen.cy),ctxtCYScreen)==ERROR_SUCCESS)
//                                             ?float(::GetSystemMetrics(SM_CYSCREEN))/szScreen.cy
//                                             :float(1.0);
// */
// 			CRegKey key;
// 			bRes=key.Open(keyMain,ctxtMainWindow,KEY_READ)==ERROR_SUCCESS
// 					&&	m_pImpl->Restore(key,xratio,yratio);
// 
//         }

		if(!bRes)
			bRes=m_pImpl->RestoreDefault();
        return bRes;
    }
	bool RestoreDefault(void)
	{
		return m_pImpl->RestoreDefault();
	}
protected:
	CImpl*	m_pImpl;
};

class CWindowStateAdapter
{
protected:
	class CImpl : public CStateBase<IState>
	{
	public:
		CImpl(HWND hWnd,int nDefCmdShow=SW_SHOWNA)
			:m_hWnd(hWnd),m_nDefCmdShow(nDefCmdShow)
		{
			assert(::IsWindow(hWnd));
		}
		virtual bool Store(IStorge& stg)
		{
            WINDOWPLACEMENT wp;
            wp.length = sizeof(WINDOWPLACEMENT);
            assert(::IsWindow(m_hWnd));
            bool bRes=false;
            if (::GetWindowPlacement(m_hWnd,&wp))
            {
                wp.flags = 0;
                if (::IsZoomed(m_hWnd))
                        wp.flags |= WPF_RESTORETOMAXIMIZED;
/*
                bRes=(::RegSetValueEx(key,ctxtPlacement,NULL,REG_BINARY,
										reinterpret_cast<CONST BYTE *>(&wp),
										sizeof(WINDOWPLACEMENT))==ERROR_SUCCESS);
*/
				bRes=(stg.SetBinary(ctxtPlacement,&wp,sizeof(WINDOWPLACEMENT))==ERROR_SUCCESS);
            }
			return bRes;
		}
		virtual bool Restore(IStorge& stg,float /*xratio*/,float /*yratio*/)
		{
            assert(::IsWindow(m_hWnd));
            WINDOWPLACEMENT wp;
/*
            DWORD dwType;
            DWORD cbData=sizeof(WINDOWPLACEMENT);
            bool bRes=(::RegQueryValueEx(key,ctxtPlacement,NULL,&dwType,
											reinterpret_cast<LPBYTE>(&wp),&cbData)==ERROR_SUCCESS)
											&&(dwType==REG_BINARY);
*/
            size_t size=sizeof(WINDOWPLACEMENT);
			bool bRes=(stg.GetBinary(ctxtPlacement,&wp,size)==ERROR_SUCCESS
						&& (size == sizeof(WINDOWPLACEMENT) ) );
            if(bRes)
                    bRes=(::SetWindowPlacement(m_hWnd,&wp)!=FALSE);
            return bRes;
		}
		virtual bool RestoreDefault(void)
		{
			::ShowWindow(m_hWnd,m_nDefCmdShow);
			return true;
		}
	protected:
		HWND	m_hWnd;
		int		m_nDefCmdShow;
	};
public:
    CWindowStateAdapter(HWND hWnd,int nDefCmdShow=SW_SHOWNOACTIVATE)
    {
		m_pImpl = new CImpl(hWnd,nDefCmdShow);
    }
	~CWindowStateAdapter(void)
	{
		assert(m_pImpl);
		m_pImpl->Release();
	}
	operator IState* (void)
	{
		return m_pImpl;
	}
protected:
	CImpl* m_pImpl;
};

class CToggleWindowAdapter
{
protected:
	class CImpl : public CStateBase<IState>
	{
	public:
		CImpl(HWND hWnd,int nDefCmdShow=SW_SHOWNA)
			:m_hWnd(hWnd),m_nDefCmdShow(nDefCmdShow)
		{
			assert(::IsWindow(hWnd));
		}
		virtual bool Store(IStorge& stg)
		{
            DWORD visible=::IsWindowVisible(m_hWnd);
/*
			return (::RegSetValueEx(key, ctxtVisible, NULL, REG_DWORD,
								reinterpret_cast<BYTE*>(&visible), sizeof(DWORD))==ERROR_SUCCESS);
//            return (key.SetValue(visible,ctxtVisible)==ERROR_SUCCESS);
*/
			return (stg.SetBinary(ctxtVisible,&visible,sizeof(DWORD))==ERROR_SUCCESS);
		}
		virtual bool Restore(IStorge& stg,float /*xratio*/,float /*yratio*/)
		{
            DWORD visible;
//          bool bRes=(key.QueryValue(visible,ctxtVisible)==ERROR_SUCCESS);
/*
			DWORD dwCount = sizeof(DWORD);
			bool bRes=(::RegQueryValueEx(key,ctxtVisible,NULL,NULL,
								reinterpret_cast<LPBYTE>(&visible),&dwCount)==ERROR_SUCCESS
									 && (dwCount == sizeof(DWORD)));
*/
			size_t size=sizeof(DWORD);
			bool bRes=(stg.GetBinary(ctxtVisible,&visible,size)==ERROR_SUCCESS
							&& (size==sizeof(DWORD)));
            if(bRes)
                    ::ShowWindow(m_hWnd, (visible!=0) ? SW_SHOWNA : SW_HIDE);
            else
                    RestoreDefault();
            return bRes;
		}
		virtual bool RestoreDefault(void)
		{
            ::ShowWindow(m_hWnd,m_nDefCmdShow);
            return true;
		}
	protected:
		HWND	m_hWnd;
		int		m_nDefCmdShow;
	};
public:
    CToggleWindowAdapter(HWND hWnd,int nDefCmdShow=SW_SHOWNOACTIVATE)
    {
		m_pImpl = new CImpl(hWnd,nDefCmdShow);
    }
	~CToggleWindowAdapter(void)
	{
		assert(m_pImpl);
		m_pImpl->Release();
	}
	operator IState* (void)
	{
		return m_pImpl;
	}
protected:
	CImpl* m_pImpl;
};

class CRebarStateAdapter
{
protected:
	class CImpl : public CStateBase<IState>
	{
	public:
		CImpl(HWND hWnd)
			:m_rebar(hWnd)
		{
			assert(::IsWindow(hWnd));
		}

		virtual bool Store(IStorge& stg)
		{
			assert(m_rebar.IsWindow());
			unsigned int bandCount=m_rebar.GetBandCount();
			for(unsigned int i=0;i<bandCount;i++)
			{
				std::basic_ostringstream<TCHAR> sstrKey;
				sstrKey<<ctxtBand<<i;
				REBARBANDINFO rbi;
				ZeroMemory(&rbi,sizeof(REBARBANDINFO));
				rbi.cbSize = sizeof(REBARBANDINFO);
				rbi.fMask = RBBIM_ID | RBBIM_COLORS |
							RBBIM_SIZE | RBBIM_STYLE
							| RBBIM_CHILDSIZE
							#if (_WIN32_IE >= 0x0400)
								| /*RBBIM_HEADERSIZE |*/ RBBIM_IDEALSIZE
							#endif
								;
				m_rebar.GetBandInfo(i, &rbi);
/*
				::RegSetValueEx(key,sstrKey.str().c_str(),NULL,REG_BINARY,
								reinterpret_cast<CONST BYTE *>(&rbi),
								rbi.cbSize);
*/
				stg.SetBinary(sstrKey.str().c_str(),&rbi,size_t(rbi.cbSize));
			}
			return true;
		}

		virtual bool Restore(IStorge& stg,float /*xratio*/,float /*yratio*/)
		{
			unsigned int bandCount=m_rebar.GetBandCount();
			for(unsigned int i=0;i<bandCount;i++)
			{
				std::basic_ostringstream<TCHAR> sstrKey;
				sstrKey<<ctxtBand<<i;
				REBARBANDINFO rbi;
				//ZeroMemory(&rbi,sizeof(REBARBANDINFO));
/*
				DWORD dwType;
				DWORD cbData=sizeof(REBARBANDINFO);
	            if((::RegQueryValueEx(key,sstrKey.str().c_str(),NULL,&dwType,
							reinterpret_cast<LPBYTE>(&rbi),&cbData)==ERROR_SUCCESS)
							&&(dwType==REG_BINARY))
*/
				size_t size=sizeof(REBARBANDINFO);
				if(stg.GetBinary(sstrKey.str().c_str(),&rbi,size)==ERROR_SUCCESS
					&& (size==sizeof(REBARBANDINFO)))
				{
					m_rebar.MoveBand(m_rebar.IdToIndex(rbi.wID), i);
					m_rebar.SetBandInfo(i, &rbi);
				}
			}
			return true;

		}
		virtual bool RestoreDefault(void)
		{
			return true;
		}
	protected:
		CReBarCtrl m_rebar;
	};
public:
    CRebarStateAdapter(HWND hWnd)
    {
		m_pImpl = new CImpl(hWnd);
    }
	~CRebarStateAdapter(void)
	{
		assert(m_pImpl);
		m_pImpl->Release();
	}
	operator IState* (void)
	{
		return m_pImpl;
	}
protected:
	CImpl* m_pImpl;
};

}//namespace sstate
#endif // __WTL_DW__SSTATE_H__

⌨️ 快捷键说明

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