Solved

How to MAX chars in EDIT Control

Posted on 2013-06-23
3
370 Views
Last Modified: 2013-06-24
How would I put a limit on the number of characters used in an Edit control?

Is there some sort of MAX CHARACTER attribute I can set? I can't find this in the docs.

Thanks!
0
Comment
Question by:edvinson
3 Comments
 
LVL 30

Assisted Solution

by:Zoppo
Zoppo earned 250 total points
ID: 39270403
Hi edvinson,

you can send the control a EM_LIMITTEXT message (or, if you use MFC, call CEdit::LimitText) to limit the amount of text which the user can enter to an edit control.

Hope that help,

ZOPPO
0
 
LVL 32

Accepted Solution

by:
sarabande earned 250 total points
ID: 39271215
to add to above comment:

the code for winapi (not mfc) is like

HWND hwnd = GetDlgItem(hwndDialog, IDC_EDIT1);
if (hwnd != NULL)
{
    SendMessage(hwnd, EM_LIMITTEXT, (WPARAM)max_chars_allowed, 0); 
}

Open in new window


assuming hwndDialog is the windows handl of your form, IDC_EDIT1 is the resource id of the control and max_chars_allowed is an integer variable containing the maximum length.

you would send the message in the handler for WM_INITDIALOG message after loading the resources.

Sara
0
 
LVL 1

Author Closing Comment

by:edvinson
ID: 39273533
Perfect solution, thanks
0

Featured Post

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.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

760 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