Search code examples
c++winapieditcontrolcharacter-limit

Remove the limit on the number of characters that can be entered into a Win32 Edit control


I've searched everywhere and it seems I can't find a solution to this problem..

My problem isn't limiting the amount of characters that can be entered into an edit control, my problem is I am limited by the size of the edit control. I want to be able to type past the size of the edit control.

I've tried extending the character limit to a high number with SendMessage and sending EM_LIMITTEXT, but that only seems to work if I want to limit it even more.

Here's an image example of my problem:

My problem

I use CreateWindowEx to create the edit control, but there doesn't seem to be an extended window style OR an edit control style that achieves what I want.


Solution

  • The style you're looking for is ES_AUTOHSCROLL. Without this style, input cannot go past the length of the edit control. With this style, text is automatically scrolled to the right by 10 characters when the input reaches the end of the control.

    You may also be interested in ES_MULTILINE, which does exactly what it says. The default (without this style) is a single-line edit control.

    All of the available styles are documented here. These are just regular window styles, not extended ones.

    Also, I am pretty sure that you cannot change these styles at runtime, after the control has been created. Therefore, make sure that they are specified when you call CreateWindowEx, or in your resource file if the control lives on a dialog.