Prev: Designing a Finite State Machine DFA Recognizer for UTF-8
Next: Displaying Information to the User (maybe HTML)
From: JCO on 19 May 2010 14:52 Using VS2008 I have an app that has an edit box that contains the Clients Age. I'm doing the validity check when the edit box looses focus. This works great when the user clicks a button that runs the application. However, if the user clicks Run App from the menu, the edit box does not loose the focus... therefore the check is not made. I can tell you that the code for File>Run does nothing more that call the ::OnFileRunapplication What's the easiest way to resolve this? Seems like I need to loose the focus of the edit box before making a call to ::OnFileRunapplication. Thanks
From: JCO on 19 May 2010 15:04 I meant to say that the code under the menu (::OnFileRunapplication) simply calls the button control (::OnBnClickedButtonRunProgram) Thanks "JCO" <someone(a)somewhere.com> wrote in message news:#AWTrR49KHA.3840(a)TK2MSFTNGP02.phx.gbl... > Using VS2008 > I have an app that has an edit box that contains the Clients Age. I'm > doing the validity check when the edit box looses focus. This works great > when the user clicks a button that runs the application. However, if the > user clicks Run App from the menu, the edit box does not loose the > focus... therefore the check is not made. > > I can tell you that the code for File>Run does nothing more that call the > ::OnFileRunapplication > > What's the easiest way to resolve this? Seems like I need to loose the > focus of the edit box before making a call to ::OnFileRunapplication. > > Thanks
From: Goran on 19 May 2010 15:40 On May 19, 8:52 pm, "JCO" <some...(a)somewhere.com> wrote: > Using VS2008 > I have an app that has an edit box that contains the Clients Age. I'm doing > the validity check when the edit box looses focus. This works great when > the user clicks a button that runs the application. However, if the user > clicks Run App from the menu, the edit box does not loose the focus... > therefore the check is not made. It looks like you should simply validate your text before executing a command, regardless of it's source (button or a menu, or an accelerator even). Your idea that you should validate when losing focus is wrong in your context (and IMHO, validation when control loses focus, in general, is wrong more often than not). Goran.
From: Joseph M. Newcomer on 19 May 2010 17:10 One of the things I discovered the hard way was that doing validation-on-focus-loss is not the best way to handle validation. So about 20 years ago, I adopted the idea of "realtime" validation; for example, that the edit control contains code to validate the age (whatever that means) and re-validates on every character typed; an example of this is my Validating Edit Control which is on my MVP Tips site, which validates the format of a floating-point number. But when you select a menu item, you don't actually lose (not loose) focus, but when the app comes up, you should lose focus when one of its controls gets focus. Note, however, that if the app doesn't actually do a SetFocus,then there is no loss-of-focus. One particularly bad feature of validation-on-focus-loss is what do you do if the value is "invalid" by whatever determines validity? If you pop up a MessageBox, this is the wrong approach, because it means you can't even hit the "cancel" button because it keeps popping up an annoying messagebox. When I have complex dialogs, I tend to do things like have a CStatic which displays an error message if any one control fails to validate; in extreme cases I've used a CListBox to display ALL the reasons that validation has failed. A variant of this is to use a ToolTip on the OK button, which I disable if any control fails validation; the tooltip displays one of reasons for validation failure. There are lots of different approaches to validation; for example, if you only want digits, you can use the ES_NUMBER property of the edit control (Property: Number=true) to make sure that illegal characters cannot be typed. If there is other validation (for example, that the age is < 120), I prefer to do these with realtime validation. joe On Wed, 19 May 2010 13:52:21 -0500, "JCO" <someone(a)somewhere.com> wrote: >Using VS2008 >I have an app that has an edit box that contains the Clients Age. I'm doing >the validity check when the edit box looses focus. This works great when >the user clicks a button that runs the application. However, if the user >clicks Run App from the menu, the edit box does not loose the focus... >therefore the check is not made. > >I can tell you that the code for File>Run does nothing more that call the >::OnFileRunapplication > >What's the easiest way to resolve this? Seems like I need to loose the >focus of the edit box before making a call to ::OnFileRunapplication. > >Thanks Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: JCO on 19 May 2010 18:41
Okay both of you agree that the Lose Focus is not a great way to do it and I agree. This is an EditBox that is set to accept only Integers because it is the Clients Age. VS2008 gives me a property to set that forces it to be an Integer only. Since this is the case, I should not have to SubClass CEdit for my purpose. This is to simple. I changed the Handler from OnFocusKill to EN_CHANGE. This seems to work just fine. This should be okay.... right? I think it should be okay because the Property that sets it to Integers only already does all of the validation I need. "Joseph M. Newcomer" <newcomer(a)flounder.com> wrote in message news:0gk8v51vln9ml0vhirgk01060qmov1kgjj(a)4ax.com... > One of the things I discovered the hard way was that doing > validation-on-focus-loss is not > the best way to handle validation. So about 20 years ago, I adopted the > idea of > "realtime" validation; for example, that the edit control contains code to > validate the > age (whatever that means) and re-validates on every character typed; an > example of this is > my Validating Edit Control which is on my MVP Tips site, which validates > the format of a > floating-point number. > > But when you select a menu item, you don't actually lose (not loose) > focus, but when the > app comes up, you should lose focus when one of its controls gets focus. > Note, however, > that if the app doesn't actually do a SetFocus,then there is no > loss-of-focus. > > One particularly bad feature of validation-on-focus-loss is what do you do > if the value is > "invalid" by whatever determines validity? If you pop up a MessageBox, > this is the wrong > approach, because it means you can't even hit the "cancel" button because > it keeps popping > up an annoying messagebox. > > When I have complex dialogs, I tend to do things like have a CStatic which > displays an > error message if any one control fails to validate; in extreme cases I've > used a CListBox > to display ALL the reasons that validation has failed. A variant of this > is to use a > ToolTip on the OK button, which I disable if any control fails validation; > the tooltip > displays one of reasons for validation failure. > > There are lots of different approaches to validation; for example, if you > only want > digits, you can use the ES_NUMBER property of the edit control (Property: > Number=true) to > make sure that illegal characters cannot be typed. If there is other > validation (for > example, that the age is < 120), I prefer to do these with realtime > validation. > joe > > On Wed, 19 May 2010 13:52:21 -0500, "JCO" <someone(a)somewhere.com> wrote: > >>Using VS2008 >>I have an app that has an edit box that contains the Clients Age. I'm >>doing >>the validity check when the edit box looses focus. This works great when >>the user clicks a button that runs the application. However, if the user >>clicks Run App from the menu, the edit box does not loose the focus... >>therefore the check is not made. >> >>I can tell you that the code for File>Run does nothing more that call the >>::OnFileRunapplication >> >>What's the easiest way to resolve this? Seems like I need to loose the >>focus of the edit box before making a call to ::OnFileRunapplication. >> >>Thanks > Joseph M. Newcomer [MVP] > email: newcomer(a)flounder.com > Web: http://www.flounder.com > MVP Tips: http://www.flounder.com/mvp_tips.htm |