Visual C++ Developer Center >
Visual C++ Forums
>
Visual C++ Language
>
Validations for a dialog based application
Validations for a dialog based application
- Hi
How do i add validations to an edit box in a dialog based application where i type the name like the first letter shud be a capital letter,no numerals or special characters and the word limit etc...
Answers
- Are you using MFC? If so you would benefit greatly from studying an MFC book.
To take your last question first, you right-click on the edit control and do 'Add Variable'. This gives your dialog class a member variable CEdit m_someeditname. Use that variable to call CEdit member functions.
m_someeditname.SetLimitText(n);
sets the text limit. A big part of MFC is to give you such functions so you do not have to send messages.
To validate input to the edit control you start by deriving a class from CEdit. And you add a message handler in that class for WM_CHAR. The flounder.com tutorial shows such a function as CFloatingEdit::OnChar. To make your CEdit-derived class work with m_someeditname you simply change CEdit to CFloatingEdit in the dialog header file.- Marked As Answer byKEERV Friday, November 06, 2009 3:52 AM
All Replies
- Thanks Scott.. but i dint understand much... :(
I googled and searched for some sample code but unable to get one clear solution.
If i want to use EM_LIMITTEXT i need to send it using SendDlgItemMessage. How do i do that? any sample code? please help.. - Are you using MFC? If so you would benefit greatly from studying an MFC book.
To take your last question first, you right-click on the edit control and do 'Add Variable'. This gives your dialog class a member variable CEdit m_someeditname. Use that variable to call CEdit member functions.
m_someeditname.SetLimitText(n);
sets the text limit. A big part of MFC is to give you such functions so you do not have to send messages.
To validate input to the edit control you start by deriving a class from CEdit. And you add a message handler in that class for WM_CHAR. The flounder.com tutorial shows such a function as CFloatingEdit::OnChar. To make your CEdit-derived class work with m_someeditname you simply change CEdit to CFloatingEdit in the dialog header file.- Marked As Answer byKEERV Friday, November 06, 2009 3:52 AM
- Thanks again Scott.. Will try that..and yes am using MFC.
- Hi KEERV,
Scott has given you a great sample and a detailed description. And I also found a good example in Codeproject for your reference:
Validating Edit Controls
Best Regards,
Nancy
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Yes Nancy thank you. I did google and had found this link and had gone through it. I found it a little difficult to understand.
After a little more of searching in the msdn forums and reading an mfc book like Scott suggested I have now found a simpler way of validating edit controls. :)
("simpler way" according to me.)


