Click here to Skip to main content
15,896,154 members
Articles / Desktop Programming / MFC

Number, Currency, Percentage Edit Control

Rate me:
Please Sign up or sign in to vote.
4.38/5 (9 votes)
4 Oct 2000 106.2K   4.5K   31  
Edit Controls that provide masking, formatting and validating for number, currency, percentage values.
//--------------------------------------------------------------------------------------/
//	Header File

//	Class:			CNumEdit			
//	Base Class:		CEdit

//	File:			NumEdit.h		
//	Revision:		A						
//	Date:			17 August 2000
//  Designed:		Ian J Hart	
//--------------------------------------------------------------------------------------/

#ifndef __NUMEDIT_H__
#define __NUMEDIT_H__

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//--------------------------------------------------------------------------------------/

class CNumEdit : public CEdit
{
// 1 - Construction
public:

	CNumEdit();	

// 2 - Destruction
public:

	virtual ~CNumEdit();

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CNumEdit)
	//}}AFX_VIRTUAL

// 3 - Message Map Functions 
protected:

	//{{AFX_MSG(CNumEdit)
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnSetfocus();
	afx_msg void OnKillFocus();	
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()

//	4 - Class Member Variables 
private:
	CToolTipCtrl* m_pToolTip;

protected:
	
	double	m_fNumber;
	int		m_dPrecision;
	bool	m_bNegValues;
	CString m_strText;

//	5 - Class Member Functions 
private:

	void Update();

protected:

    void	Get_EditCtrl_Text();
	void	Set_EditCtrl_Text(CString strText);
	bool	Validate_Char(UINT nChar);
	double	Text_To_Number(CString strText);
	CString Number_To_Text(double fNumber);
	
//	6 - Class Creation/Initialisation

public:	

	void Init	  (double	fNumber		=0.00,	
				   int		dPrecision	=2,
				   bool		bNegValues =true);

	void Set_Data (double	fNumber,	
				   int		dPrecision,
				   bool		bNegValues);


// 7 - Interface 

public:	


	CString Get_Number_Text();

	double	Get_Number();
	void	Set_Number(double fNumber);

};
#endif 
//--------------------------------------------------------------------------------------/

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
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions