Click here to Skip to main content
15,895,142 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 75K   3.6K   36  
Masked numeric edit ActiveX control.
/////////////////////////////////////////////////////////////////////////////////////////
//	Project:		SP Data Formatting Library 1.5
//
//	File:			FloatEFormatter.cpp		
//
//	Developer(s):	Sergei Pavlovsky
//					sergei_vp@hotmail.com
//					Copyright (c) 2004-2005
//
//	Description:	Implementation of the formatter for float values of the exponent 
//					format.
//
//	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.
/////////////////////////////////////////////////////////////////////////////////////////

#include "StdAfx.h"
#include "FloatEFormatter.h"
#include "../resource.h" // ???

namespace SP
{

/////////////////////////////////////////////////////////////////////////////////////////
// CFloatEFormatter class implementation
/////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////
// Helpers: Common

UINT_PTR CFloatEFormatter::GetDigitalPatterns(
									const CRealEDigitalPattern** prgPatterns) const
{
	ATLASSERT( !prgPatterns || 
			   !::IsBadWritePtr(prgPatterns, PTC_DIGITAL * sizeof(CNumericPattern*)) );

	if ( prgPatterns )
	{
		prgPatterns[0] = &m_patternPosNumber;
		prgPatterns[1] = &m_patternNegNumber;
		prgPatterns[2] = &m_patternPosZero;
		prgPatterns[3] = &m_patternNegZero;
	}

	return PTC_DIGITAL;
}

/////////////////////////////////////////////////////////////////////////////////////////
// Operations: Kind

CDataFormatter::TypeEnum CFloatEFormatter::GetType() const
{
	return DT_FLOAT;
}

/////////////////////////////////////////////////////////////////////////////////////////
// Helpers: Formatting & scanning

const CRealEDigitalPattern& CFloatEFormatter::GetPatternForExponent(char nSign) const
{
	if ( nSign > 0 )
		return m_patternPosNumber;

	if ( nSign < 0 )
		return m_patternNegNumber;
	
	return m_patternPosZero;
}

/////////////////////////////////////////////////////////////////////////////////////////
// CFormatter class implementation
/////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////
// Class factories

CDataFormatter* CFormatter::CreateForEFloat(DWORD fTraits, LCID lcid) 
{
	// Create formater object
	CFloatEFormatter*  pFormater = new CFloatEFormatter(lcid, fTraits);
	ATLASSERT( pFormater );
	if ( !pFormater )
	{
		SP::AccountError(SP::AE_LOG|SP::AE_SETMSG, IDS_ELS_CRT, 2, IDS_ELR_OUTOFMEMORY);
		return NULL;
	}

	pFormater->AddRef();

	return pFormater;
}

CDataFormatter* CFormatter::CreateForEFloat(LPCTSTR lpcszMask, DWORD fTraits, 
											LCID lcid) 
{
	// Create formater object
	CFloatEFormatter* pFormater = new CFloatEFormatter(lcid, fTraits);
	ATLASSERT( pFormater );
	if ( !pFormater )
	{
		SP::AccountError(SP::AE_LOG|SP::AE_SETMSG, IDS_ELS_CRT, 2, IDS_ELR_OUTOFMEMORY);
		return NULL;
	}

	pFormater->AddRef();

	// Set mask
	bool bResult = pFormater->SetMask(lpcszMask);
	ATLASSERT( bResult );
	if ( !bResult )
	{
		pFormater->Release();

		SP::AccountError(SP::AE_LOG, IDS_ELS_SPCONVERSION, 2, IDS_ERDF_SETMASK);
		return NULL;
	}

	return pFormater;
}

}; // namespace SP

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