Visual C++ Developer Center > Visual C++ Forums > Visual C++ Language > Validations for a dialog based application
Ask a questionAsk a question
 

AnswerValidations for a dialog based application

  • Wednesday, November 04, 2009 12:25 PMKEERV Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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

  • Wednesday, November 04, 2009 4:31 PMScott McPhillipsMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    • Marked As Answer byKEERV Friday, November 06, 2009 3:53 AM
    • Unmarked As Answer byKEERV Thursday, November 05, 2009 6:54 AM
    • Marked As Answer byKEERV Thursday, November 05, 2009 3:41 AM
    •  
  • Thursday, November 05, 2009 2:49 PMScott McPhillipsMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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

  • Wednesday, November 04, 2009 4:31 PMScott McPhillipsMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    • Marked As Answer byKEERV Friday, November 06, 2009 3:53 AM
    • Unmarked As Answer byKEERV Thursday, November 05, 2009 6:54 AM
    • Marked As Answer byKEERV Thursday, November 05, 2009 3:41 AM
    •  
  • Thursday, November 05, 2009 3:41 AMKEERV Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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..

  • Thursday, November 05, 2009 2:49 PMScott McPhillipsMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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
    •  
  • Friday, November 06, 2009 3:52 AMKEERV Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks again Scott.. Will try that..and yes am using MFC.
  • Friday, November 06, 2009 7:30 AMNancy ShaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.
  • Friday, November 06, 2009 12:10 PMKEERV Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.)