Solved

Max/min size allowed in edit box

Posted on 1998-11-09
6
407 Views
Last Modified: 2013-11-20
How can I set a maximum or minimum length of data to be typed in an edit box of a dialog box?  I have a pop up dialog box on each new document that prompts for player names.  What I'd like to do is set the edit box to accept nothing that is under 1 or over 10 letters long.
0
Comment
Question by:Mephisto
  • 3
  • 3
6 Comments
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
The minimum's a tough one!  There's not a standard way to do this except through some sort of masked edit box.  The maximum's easy though, use SetLimitText.

Phillip

0
 

Author Comment

by:Mephisto
Comment Utility
How/where do I use the SetLimitText() function?  I'm a beginner and was only able to create the dialog box through trial and error and luck.. And don't know how to use the SetLimitText() function.
0
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
I hope you have used ClassWizard to create your CDialog.  If not, you need to learn how.

If you have, choose your class.  Select the 'Member Variable' tab.  Click on the edit control that you want to limit.  Now add a variable for this class making the name something like 'm_ctlFirstName' and the type will be CEdit.  Then 'OK' out of class wizard.

Now you have a member variable tied to the control through the DDX property area.  To limit your text, override the OnInitDialog once again through the ClassWizard and then click the 'Edit Function' button.  Inside of that function, you will want to do something like:  

m_ctlFirstName.SetLimitText( 10 );

OK?

Phillip
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:Mephisto
Comment Utility
Sorry to reject again, I just wanted to make sure I could get this question answered.  The problem is that the data from the dialog box needs to be saved as a CString because I later use the variable as a CString for output onto the screen.  Is there a way I can create the variable as a CEdit to limit the text and then convert it to a CString?
0
 

Author Comment

by:Mephisto
Comment Utility
I figured it out (that you can add 2 variables to each ID, one a CEdit, one a CString)..  Thanks for your time..  slap an answer on here and i'll give you the points...
0
 
LVL 7

Accepted Solution

by:
psdavis earned 10 total points
Comment Utility
Glad I was able to help!

Phillip
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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

12 Experts available now in Live!

Get 1:1 Help Now