Newsgroups: comp.windows.ms.programmer
Path: utzoo!utgpu!watserv1!watmath!hyper.hyper.com!bonneau
From: bonneau@hyper.hyper.com (Paul Bonneau)
Subject: Re: Can I use EN_KILLFOCUS for field-checking?
Message-ID: <1991May24.173226.15131@hyper.hyper.com>
Reply-To: bonneau@hyper.UUCP (Paul Bonneau,,)
Organization: HyperCube Inc.
References: <17176@chopin.udel.edu>
Date: Fri, 24 May 1991 17:32:26 GMT

In article <17176@chopin.udel.edu> garrett@chopin.udel.edu (Joel Garrett) writes:
>I want to be able to error check the edit controls in a dialog box, ie if they
>enter something that isn't a valid floating-point number, I want to be able to
>keep the user in that field until they enter a valid entry.  To do this, I
>tried using the EN_KILLFOCUS message to let me know when the user was leaving
>a certain input field, at which time I could check the contents of that field
>and if they weren't ok, I'd do somthing like this:
>
>MessageBeep(0);
>SetFocus(hwndCtrl);
>SendDlgItemMessage(hDlg, nCtrlID, EN_SETSEL, 0, MAKELONG(0,32767));
>
The problem is that you are trying the set the focus back on
a kill focus notification.  SetFocus() is *not* reentrant, and
things will get truly screwed up.

We have many dialog boxes with edits, and unless it is
critical, we let the user type in whatever he/she want, but
don't validate until the OK button is hit.

For those dialogs that need to track the edit contents, we
use the EN_CHANGE message and validate character by character.
You have to be more careful with this approach, since interim
values in the edit may not be valid final values.

cheers - Paul Bonneau.
