WM_KILLFOCUS
-
Hi, I have to validate a field entry on kill focus of the edit control.If the user enters invalid data, a error message box should pop up and focus should remain on the edit control only so as to allow user to change the wrong entry. The problem is, this validation should not occur when user is exiting from the dialog like pressing cancel or exit. But when he clicks on the cancel button, kill foucs gets called and if the user has entered wrong data, error message will pop. Infact he won't be able to exit until he corrects the entry, which is ridiculous. To avoid this problem, I switched validation from kill focus to SetFocus of the next control. The program behaviour is -- User enters data in Control A Then he puts cursor on Control B. Control B::On Set Focus validates the ControlA:data. IF wrong, pops up the message box and sets the focus to Control A. But whenever user presess OK on the message box, focus again goes to Control B rather than going to Control A. Again validate is called and again the message box pops up. This goes in loop. I didn't want to put the validations on En_change or use a bool vble for skipping the validations next time. Any ideas will help a lot both on killfocus and setfocus front.
-
Hi, I have to validate a field entry on kill focus of the edit control.If the user enters invalid data, a error message box should pop up and focus should remain on the edit control only so as to allow user to change the wrong entry. The problem is, this validation should not occur when user is exiting from the dialog like pressing cancel or exit. But when he clicks on the cancel button, kill foucs gets called and if the user has entered wrong data, error message will pop. Infact he won't be able to exit until he corrects the entry, which is ridiculous. To avoid this problem, I switched validation from kill focus to SetFocus of the next control. The program behaviour is -- User enters data in Control A Then he puts cursor on Control B. Control B::On Set Focus validates the ControlA:data. IF wrong, pops up the message box and sets the focus to Control A. But whenever user presess OK on the message box, focus again goes to Control B rather than going to Control A. Again validate is called and again the message box pops up. This goes in loop. I didn't want to put the validations on En_change or use a bool vble for skipping the validations next time. Any ideas will help a lot both on killfocus and setfocus front.
Hi there, All you have to do is create a handler for trapping the EN_KILLFOCUS so that you get the message that the edit control is loosing the focus. So inside the handler put the MessageBox that you want to popup. When the user clicks on OK on the dialog box, edit control looses the focus. So to ensure that the focus is on the edit control, create a control variable for the edit control suppose(m_control) do the following after the statement following the MessageBox CPoint set(0,0); m_control.SetFocus(); m_control.SetCaretPos(set); :)
-
Hi, I have to validate a field entry on kill focus of the edit control.If the user enters invalid data, a error message box should pop up and focus should remain on the edit control only so as to allow user to change the wrong entry. The problem is, this validation should not occur when user is exiting from the dialog like pressing cancel or exit. But when he clicks on the cancel button, kill foucs gets called and if the user has entered wrong data, error message will pop. Infact he won't be able to exit until he corrects the entry, which is ridiculous. To avoid this problem, I switched validation from kill focus to SetFocus of the next control. The program behaviour is -- User enters data in Control A Then he puts cursor on Control B. Control B::On Set Focus validates the ControlA:data. IF wrong, pops up the message box and sets the focus to Control A. But whenever user presess OK on the message box, focus again goes to Control B rather than going to Control A. Again validate is called and again the message box pops up. This goes in loop. I didn't want to put the validations on En_change or use a bool vble for skipping the validations next time. Any ideas will help a lot both on killfocus and setfocus front.
Validating data during a
WM_KILLFOCUS
message indicates a bad design. That message gets sent in too many situations so picking and choosing which one(s) you are interested in will lead to trouble. The most reliable way of validating data on a dialog box is to check the state of each control anytime a control changes. Set up a "change" handler for each control and do the validating in it. If all conditions are met, only then do you enable the OK button. I do this for each of my dialogs. It is very clean and reliable. Read here for more.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Hi, I have to validate a field entry on kill focus of the edit control.If the user enters invalid data, a error message box should pop up and focus should remain on the edit control only so as to allow user to change the wrong entry. The problem is, this validation should not occur when user is exiting from the dialog like pressing cancel or exit. But when he clicks on the cancel button, kill foucs gets called and if the user has entered wrong data, error message will pop. Infact he won't be able to exit until he corrects the entry, which is ridiculous. To avoid this problem, I switched validation from kill focus to SetFocus of the next control. The program behaviour is -- User enters data in Control A Then he puts cursor on Control B. Control B::On Set Focus validates the ControlA:data. IF wrong, pops up the message box and sets the focus to Control A. But whenever user presess OK on the message box, focus again goes to Control B rather than going to Control A. Again validate is called and again the message box pops up. This goes in loop. I didn't want to put the validations on En_change or use a bool vble for skipping the validations next time. Any ideas will help a lot both on killfocus and setfocus front.