PRB: WM_SETTEXT Ignores EM_LIMITTEXT Edit Control Text Limit

ID Number: Q75865

3.00

WINDOWS

Summary:

SYMPTOMS

When the WM_SETTEXT message is used to place text into an edit

control, more text than the text length limit specified in an

EM_LIMITTEXT message can be placed into the control.

RESOLUTION

This is the designed behavior for these messages. This allows an

application to create an edit control where only the first "n"

characters can be entered by the user, and the remainder of the

text is specified by the application ("n" is specified in the

EM_LIMITTEXT message).

More Information:

There is a limitation to this method. If the application specifies more

text than is specified in the EM_LIMITTEXT message, the user can edit

the entire contents of the edit control.

There are two ways to work around this limitation:

1. Erase all text from the edit control before allowing the user to

enter text.

2. After each WM_SETTEXT message, truncate the edit control text to

less than the limit specified in the EM_LIMITTEXT message.

The edit control will enforce the length limit if the amount of text

in the control is less than the limit. Using a WM_SETTEXT message

allows the application to violate the limit.