Solved

MFC: verifying Edit Control input

Posted on 2008-06-18
3
1,268 Views
Last Modified: 2013-11-20
I'm having some trouble verifying MFC Edit Box data (the box where users type in data). Here's what I need to verify:

- the user types an integer into the edit box, which can be negative
- the verification function should ensure the integer is within a certain range
- if it is an illegal value, it must be changed to some default legal value

The verification function is trivial, but what Edit Box event it is attached to is causing issues. Right now I have the input verification even attached to "EN_CHANGE" but that seems to be causing problems since it runs on every character types. Is there a more appropriate input to attach the verification function to?

Is there a way to not verify the Edit Box data until the user is done inputting? Perhaps by hitting enter or something?
0
Comment
Question by:Fippy_Darkpaw
  • 2
3 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 21814778
See http://www.codeproject.com/KB/edit/ValidatingTextBoxControls.aspx ("Validating Edit Controls") - this article comes with full source code and demonstrates how to do that.
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 100 total points
ID: 21814807
Sorry, wrong link, the above is managed code. See http://www.codeproject.com/KB/edit/validatingedit.aspx ("Validating Edit Controls"). The same applies, full source code - even the author is the same person.
0
 
LVL 19

Accepted Solution

by:
alb66 earned 150 total points
ID: 21819880
You must handle EN_KILLFOCUS:

BEGIN_MESSAGE_MAP(CYourDlg, CDialog)
      ON_EN_KILLFOCUS(IDC_EDIT1, OnEnKillfocusEdit1)
END_MESSAGE_MAP()

void CYourDlg::OnEnKillfocusEdit1()
{
      // do something here...
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 9 94
firstChar challenge 13 110
Sed question 2 69
Least Squares Curve Fitting 4 61
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now