Click here to Skip to main content
15,885,875 members
Articles / Desktop Programming / ATL

SP Numeric Edit Control

Rate me:
Please Sign up or sign in to vote.
4.78/5 (11 votes)
16 Nov 200511 min read 74.7K   3.6K   36  
Masked numeric edit ActiveX control.
/////////////////////////////////////////////////////////////////////////////////////////
//	Project:		SP ATL Extensions 1.3
//
//	File:			spOlePersist.h		
//
//	Developer(s):	Sergei Pavlovsky
//					sergei_vp@hotmail.com
//					Copyright (c) 2004-2005
//
//	Description:	CPersistImpl class template declaration.
//					CPersistStreamInitImpl class template declaration.
//					CPersistStorageImpl class template declaration.
//
//	Platforms:		Win32, ATL
//
//	This code may be used in compiled form in any way you desire. This file may be 
//	redistributed unmodified by any means PROVIDING it is not sold for profit without 
//	the authors written consent, and providing that this notice and the authors name 
//	is included. If the source code in this file is used in any commercial application 
//	then acknowledgement must be made to the author of this file (in whatever form 
//	you wish).
//
//	This file is provided "as is" with no expressed or implied warranty. The author 
//	accepts no liability for any damage/loss of business that this product may cause.
/////////////////////////////////////////////////////////////////////////////////////////

#pragma once

namespace SP
{

/////////////////////////////////////////////////////////////////////////////////////////
// CPersistImpl class template
/////////////////////////////////////////////////////////////////////////////////////////

template < class T >
class ATL_NO_VTABLE CPersistImpl : public IPersist
{
// Implementation: IPersist 
public:
	STDMETHOD(GetClassID)(CLSID* pClassID)
	{
		if ( !pClassID )
			return E_POINTER;

		T* pThis = static_cast<T*>(this);

		return pThis->_Persist_GetClassID(pClassID);
	}
};

/////////////////////////////////////////////////////////////////////////////////////////
// CPersistStreamInitImpl class template
/////////////////////////////////////////////////////////////////////////////////////////

template < class T >
class ATL_NO_VTABLE CPersistStreamInitImpl : public IPersistStreamInit
{
// IPersist
public:	
	STDMETHOD(GetClassID)(CLSID* pClassID)
	{
		ATLTRACE( ATL::atlTraceControls, 2, _T("SP::CPersistStreamInitImpl::GetClassID\n") );

		if ( !pClassID )
			return E_POINTER;

		T* pThis = static_cast<T*>(this);

		return pThis->_Persist_GetClassID(pClassID);
	}

// Implementation: IPersistStream
public:
	STDMETHOD(IsDirty)()
	{
		ATLTRACE( ATL::atlTraceControls, 2, _T("SP::CPersistStreamInitImpl::IsDirty\n") );

		T* pThis = static_cast<T*>(this);

		return pThis->_Persist_IsDirty();
	}

	STDMETHOD(Load)(LPSTREAM piStream)
	{
		ATLTRACE( ATL::atlTraceControls, 2, _T("SP::CPersistStreamInitImpl::Load\n") );

		if ( !piStream )
			return E_INVALIDARG;

		T* pThis = static_cast<T*>(this);

		return pThis->_PersistStream_Load(piStream);
	}

	STDMETHOD(Save)(LPSTREAM piStream, BOOL fClearDirty)
	{
		ATLTRACE( ATL::atlTraceControls, 2, _T("SP::CPersistStreamInitImpl::Save\n") );

		if ( !piStream )
			return E_INVALIDARG;

		T* pThis = static_cast<T*>(this);

		return pThis->_PersistStream_Save(piStream, fClearDirty);
	}

	STDMETHOD(GetSizeMax)(ULARGE_INTEGER* pcbSize)
	{
		ATLTRACE( ATL::atlTraceControls, 2, _T("SP::CPersistStreamInitImpl::GetSizeMax\n") );

		if ( !pcbSize )
			return E_POINTER;

		T* pThis = static_cast<T*>(this);

		return pThis->_PersistStream_GetSizeMax(pcbSize);
	}

// Implementation: IPersistStreamInit
public:
	STDMETHOD(InitNew)()
	{
		ATLTRACE( ATL::atlTraceControls, 2, _T("SP::CPersistStreamInitImpl::InitNew\n") );

		T* pThis = static_cast<T*>(this);

		return pThis->_Persist_InitNew();
	}
};

/////////////////////////////////////////////////////////////////////////////////////////
// PersistStorageImpl class template
/////////////////////////////////////////////////////////////////////////////////////////

template < class T >
class ATL_NO_VTABLE CPersistStorageImpl : public IPersistStorage
{
// IPersist
public:	
	STDMETHOD(GetClassID)(CLSID* pClassID)
	{
		ATLTRACE( ATL::atlTraceControls, 2, _T("SP::CPersistStorageImpl::GetClassID\n") );

		if ( !pClassID )
			return E_POINTER;

		T* pThis = static_cast<T*>(this);

		return pThis->_Persist_GetClassID(pClassID);
	}

// Implementation: IPersistStorage
public:
	STDMETHOD(IsDirty)()
	{
		ATLTRACE( ATL::atlTraceControls, 2, _T("SP::CPersistStorageImpl::IsDirty\n") );

		T* pThis = static_cast<T*>(this);

		return pThis->_Persist_IsDirty();
	}

	STDMETHOD(InitNew)(IStorage* piStorage)
	{
		ATLTRACE( ATL::atlTraceControls, 2, _T("SP::CPersistStorageImpl::InitNew\n") );

		if ( !piStorage )
			return E_INVALIDARG;

		T* pThis = static_cast<T*>(this);

		return pThis->_PersistStorage_InitNew(piStorage);
	}

	STDMETHOD(Load)(IStorage* piStorage)
	{
		ATLTRACE( ATL::atlTraceControls, 2, _T("SP::CPersistStorageImpl::Load\n") );

		if ( !piStorage )
			return E_INVALIDARG;

		T* pThis = static_cast<T*>(this);

		return pThis->_PersistStorage_Load(piStorage);
	}

	STDMETHOD(Save)(IStorage* piStorage, BOOL fSameAsLoad)
	{
		ATLTRACE( ATL::atlTraceControls, 2, _T("SP::CPersistStorageImpl::Save\n") );

		if ( !piStorage )
			return E_INVALIDARG;

		T* pThis = static_cast<T*>(this);

		return pThis->_PersistStorage_Save(piStorage, fSameAsLoad);
	}

	STDMETHOD(SaveCompleted)(IStorage* piStorage)
	{
		ATLTRACE( ATL::atlTraceControls, 2, _T("SP::CPersistStorageImpl::SaveCompleted\n") );

		if ( !piStorage )
			return E_INVALIDARG;

		T* pThis = static_cast<T*>(this);

		return pThis->_PersistStorage_SaveCompleted(piStorage);
	}

	STDMETHOD(HandsOffStorage)(void)
	{
		ATLTRACE( ATL::atlTraceControls, 2, _T("SP::CPersistStorageImpl::HandsOffStorage\n") );

		T* pThis = static_cast<T*>(this);

		return pThis->_PersistStorage_HandsOffStorage();
	}
};

}; // SP namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Ukraine Ukraine
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions