Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

MFC: verifying Edit Control input

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to event 3 102
Updating statistics with error notification email in SQL server 4 109
Authenticate using sesu from script 7 56
C++ help/ Toy problem 19 30
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

860 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