Solved

MFC: verifying Edit Control input

Posted on 2008-06-18
3
1,257 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

708 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

11 Experts available now in Live!

Get 1:1 Help Now