Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to MAX chars in EDIT Control

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

609 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