?
Solved

How to MAX chars in EDIT Control

Posted on 2013-06-23
3
Medium Priority
?
403 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 1000 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 35

Accepted Solution

by:
sarabande earned 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

764 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