Solved

MFC: verifying Edit Control input

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

770 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