Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

CFilterEdit: Use Regular Expressions to Filter Your Input

, 3 Oct 2011
The definitive approach to filtering input text. Includes configurable error display.
#include "StdAfx.h"
#include "UIntRangeEdit.h"

namespace FilterEdit
{
CUIntRangeEdit::CUIntRangeEdit () :
	CUIntEdit (),
	m_uiLower (0),
	m_uiHigher (0),
	m_uiInc (1)
{
}

CUIntRangeEdit::CUIntRangeEdit (const unsigned int uiLower,
	const unsigned int uiHigher) :
	CUIntEdit (),
	m_uiLower (uiLower),
	m_uiHigher (uiHigher),
	m_uiInc (1)
{
}

CUIntRangeEdit::~CUIntRangeEdit ()
{
}

void CUIntRangeEdit::SetRange (const unsigned int uiLower,
	const unsigned int uiHigher)
{
	m_uiLower = uiLower;
	m_uiHigher = uiHigher;
}

void CUIntRangeEdit::SetIncrement (const unsigned int uiInc)
{
	m_uiInc = uiInc;
}

void CUIntRangeEdit::Increment (int iInc)
{
	unsigned int uiVal = GetValue ();
	CString strUInt;

	uiVal += iInc > 0 ? m_uiInc : m_uiInc * -1;

	// Be helpful: Start at m_uiLower if no text in control
	if (iInc > 0 && uiVal < m_uiLower) uiVal = m_uiLower;

	strUInt.Format (_T("%d"), uiVal);

	if (SemanticCheck (strUInt))
	{
		SetWindowText (strUInt);
	}
}

bool CUIntRangeEdit::SemanticCheck (const CString &strText,
	CString * /*pstrErrorMsg = 0*/)
{
	unsigned int uiVal = _tstoi (strText);

	// Now we can do the semantic validation
	return uiVal >= m_uiLower && uiVal <= m_uiHigher;
}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ben Hanson
Software Developer (Senior)
United Kingdom United Kingdom
I started programming in 1983 using Sinclair BASIC, then moving on to Z80 machine code and assembler. In 1988 I programmed 68000 assembler on the ATARI ST and it was 1990 when I started my degree in Computing Systems where I learnt Pascal, C and C++ as well as various academic programming languages (ML, LISP etc.)
 
I have been developing commercial software for Windows using C++ for 15 years.

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 3 Oct 2011
Article Copyright 2004 by Ben Hanson
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid