Pastable Numeric Edit Control
Posted
by Corey Spagnoli
on January 15th, 1999
I wrote this control to replace the boring edit controls we were using for entering numbers. I have included source files, a demo project, and a demo executable for this control.
I hope someone else can get some use out of this code, too. :-)
Display Mode
Edit Mode
How to include in your project
- Copy NumEdit.cpp and NumEdit.h into your project directory.
- Add NumEdit.cpp and NumEdit.h to your project.
How to use
- Create an edit control on your dialog.
- Declare a variable in your dialog class, like this:
cNumericEditCtrl m_NumericEdit; - In OnInitDialog, call SubclassDlgItem, like this:
m_NumericEdit.SubclassDlgItem(IDC_NUMERIC_EDIT, this); // Use your edit control ID here - Set the prefix, suffix, # decimals, and whether commas should be displayed using the following member functions:
void SetAttributes(short NumDecimalPlaces, BOOL DisplayCommas = TRUE);
void SetPrefix(CString Prefix);
void SetSuffix(CString Suffix);
- Set (optional) and retrieve the numeric value within your dialog as needed using the following member functions:
double GetNumericValue();
void SetNumericValue(double NumericValue);
Download compiled demo app (no project files) - 89 KB

Comments
a fatal bug
Posted by Legacy on 08/30/2003 12:00amOriginally posted by: hbAi
if a number such as 0.032 is typed in a text box ,when the box lose focus, the number 0.032 will be multiply 10^m_NumDecimalPlaces, i.e when m_NumDecimalPlaces is 3 the number will be 32 in the text box which lose focus.
-
Replya coorection
Posted by rachid1245 on 10/09/2007 08:36amHi everybody, Before excuse me for my bad English the problem in "a fatal bug" refers to the function SetNumericText(BOOL ShowFormatting) in fcvt(m_NumericValue,m_NumDecimalPlaces,&decimal,&sign)decimal can be <0, so in for(loop=0;loop
Reply
ExEditors Library
Posted by Legacy on 03/19/2002 12:00amOriginally posted by: Mike Philips
ReplyThere is deen for checking "-" (minus), if it is already used.
Posted by Legacy on 06/25/2001 12:00amOriginally posted by: Avtandil Adamia
ReplyOnKillFocus - small bug
Posted by Legacy on 04/11/2001 12:00amOriginally posted by: Whitney Arnold
ReplyNotifications: problem solved
Posted by Legacy on 03/25/1999 12:00amOriginally posted by: Roel Schroeven
The dialog that owns the control didn't receive notifications for EN_KILLFOCUS, EN_SETFOCUS and EN_CHANGE. That problem is now solved. Here are the changes you need to apply to make it work:
Change ON_CONTROL_REFLECT to ON_CONTROL_REFLECT_EX for the three notifications in the message map in NumEditC.cpp. Change the type of the three message handler functions in NumEditC.h from afx_msg void to afx_msg BOOL, and from void to BOOL in NumEditC.cpp. Now edit the function bodies so that they return FALSE. That's it.
ReplyEN_CHANGE Notification
Posted by Legacy on 01/27/1999 12:00amOriginally posted by: Steven M. McNeese
I am unable to get notification for messages on the edit control. I tried mapping a function to the EN_CHANGE using the class wizard for the control on the dialog. What am I doing wrong?
Reply