The Solutions
The first thing I include is a validating edit control. This particular control
solves a problem many users ask for: an edit control that validates floating-point
input. However, you can replace the FSM with one that validates dates, times,
Social Security Numbers, or any other textual form you can parse. The validation
does not have to be limited to simple parsing, although it is clear from the
fact that every change initiates a validation that you do not want to do some
sort of database lookup on every character. In such a case, you would more likely
do the validation on the WM_KILLFOCUS (OnKillFocus) event. But
that's a different problem than the one this control addresses.
The way I handle this is to handle the reflected WM_COMMAND/EN_CHANGE
message. When the contents change, I read the entire string and reparse it. This
is one of the methodological changes from traditional getch-style input
where you could simply run the FSM on each keystroke. In Windows, the keystrokes
have nothing to do with the order of the content of the edit control, because
the user can reposition the input caret anywhere in the string. So the entire
string must be reparsed, from the start, each time.