Solved

How to MAX chars in EDIT Control

Posted on 2013-06-23
3
393 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
[X]
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
3 Comments
 
LVL 31

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 34

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

729 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