Click here to Skip to main content
13,259,779 members (48,377 online)
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 17 Aug 2000

Timed Update Edit Control

, 9 Sep 2013
Rate this:
Please Sign up or sign in to vote.
An edit control to periodically validate and reformat its contents.

Sample Image - TimedUpdateEdit.gif


This article presents an abstract class, TEditTimedUpdate, derived from MFC's CEdit that provides periodic validation and reformatting functionality. When the user has not typed into the edit control for a specified time (the default is two seconds) the edit control will validate and reformat the contents, updating the control text with the revised value.

Two additional classes are provided for demonstration purposes. TEditAngle shows the implementation of an edit control to accept an angle in degrees. The displayed text is formatted with a small degree symbol following the number and is validated to be within the range 0-360. TEditDistance demonstrates prefix and suffix formatting text.

All the code for handling the prefix and suffix texts are handled in the abstract base class, so data exchange to a floating point using DDX_Text(pDX, IDC_ANGLE1, m_lfAngle1); is supported.

To implement your own validation classes, simply inherit a new class from TEditTimedUpdate, pass in optional text strings for the prefix and suffix text, and the update period in seconds, and overload the AdjustValue virtual function.

class TEditAngle : public TEditTimedUpdate
    virtual void AdjustValue(CString &strValue);

    virtual ~TEditAngle();


static const unsigned char szDegrees[] = {(unsigned char)176,0};

TEditAngle::TEditAngle() : TEditTimedUpdate(NULL, (char*)szDegrees)


void TEditAngle::AdjustValue(CString &strValue)
    double  lfValue;
    LPTSTR  pStopString;

    lfValue = _tcstod(strValue, &pStopString);
    if (lfValue < 0.001)
        lfValue = 0.0;
    else if (lfValue > 360.0)
        lfValue = 360.0;

    strValue.Format("%.2f", lfValue);

When the value has been validated, the control sends a WM_NOTIFY message with a NM_EDITTIMEDUPDATE to the parent window. The parent window should respond to this message to perform dynamic processing instead of the usual NM_CHANGE.

There's not too much more to say. I think this is a great class that is very simple to use and provides a very rich user interface - but then I'm probably biased ;). It also solves all the problems will allowing non-integer numeric data entry and validates as the user enters data rather than waiting for the horrible validation messages created by MFC's DDV_ mechanism.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Craig Henderson
Technical Lead
United Kingdom United Kingdom
Craig graduated with a B.SC. Honours in Computing for Real Time Systems from the University of the West of England, Bristol in 1995 after completing an HND in Computing in 1993.

You may also be interested in...


Comments and Discussions

QuestionGreat control Pin
Michael N Haephrati (האפרתי)7-Jan-15 13:05
professionalMichael N Haephrati (האפרתי)7-Jan-15 13:05 
QuestionThis is a nice control Pin
Flaviu210-Sep-13 3:25
memberFlaviu210-Sep-13 3:25 
NewsThis is an OLD article Pin
Craig Henderson9-Sep-13 0:10
professionalCraig Henderson9-Sep-13 0:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 9 Sep 2013
Article Copyright 2000 by Craig Henderson
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid