Want to limit string length in an edit control

Want to limit string length in an edit control

Post by scs0 » Fri, 19 May 2006 00:49:01


I want to limit the length of a string that the user can insert into an
edit control. I looked into using the DDX_TEXT_LEN macro, but when I
tried it seemed to do was beep on failure. The string in the edit
control was not returned to a valid string! So what's the point of
DDX_TEXT_LEN?

I can't figure out the proper way of doing this. So instead of that I
am going to do this manually using the edit control's EN_CHANGE
message. I'll cache the string's previous valid value and replace it
in EN_CHANGE when the user inputs a string that's too large. I would
like to restore the selection and cursor position that may exist in the
control, but the last time I tried doing that the functions didn't seem
to respond to my commands.

What do I need to do to restore the selection and cursor position in an
edit control? I can't believe that Microsoft would have dropped the
ball and not provide a simple and consistent way of doing this. Surely
there's some sort of notification that reports what the control's
string is about to become so that the application can be setup to
reject the change.
 
 
 

Want to limit string length in an edit control

Post by Igor Tande » Fri, 19 May 2006 00:58:50


EM_LIMITTEXT
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925