Click here to Skip to main content
15,896,118 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:			CCurrencyEdit			
//	Base Classe:	CNumEdit

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

#ifndef __CURRENCYEDIT_H__
#define __CURRENCYEDIT_H__

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

#include "NumEdit.h"
//--------------------------------------------------------------------------------------/

class CCurrencyEdit : public CNumEdit  
{
public:
// 1 - Construction
	CCurrencyEdit();

// 2 - Destruction 
	virtual ~CCurrencyEdit();

protected:
// 3 - Message Map Functions

	//{{AFX_MSG(CNumEdit)
	afx_msg void OnLButtonUp(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:
	bool	m_bEdit_Has_Focus;
	CString m_strCurrency;
	TCHAR	m_chCurrency_Symbol;


//	5 - Class Member Functions
private:

	void Update();
	CString Number_To_Currency(double fNumber);


//	6 - Class Creation/Initialisation

public:

	void Init	(double	fNumber			  = 0.00,
				 int	dPrecision		  = 2,
				 bool	bNeg_Values		  = true,
				 TCHAR	chCurrency_Symbol ='$');

	void Set_Data(double	fNumber,	
				  int		dPrecision,
				  bool		bNeg_Values,
				  TCHAR		chCurrency_Symbol);
	

// 7 - Interface

public:
	
	CString Get_Currency_Text();

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

	TCHAR	Get_Currency_Symbol();
	void	Set_Currency_Symbol(TCHAR chCurrency_Symbol);
};
//--------------------------------------------------------------------------------------/
#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