Microsoft KB Archive/66362

PRB: Multiline Edit Controls UAE If Resizing Changes LineCount

PSS ID Number: Q66362 Article last modified on 04-26-1993

3.00 WINDOWS

Summary:

SYMPTOMS Multiline edit controls in Windows version 3.0 may cause an unrecoverable application error (UAE) when a key is pressed immediately after the control is resized.

CAUSE The error will occur only in edit controls with wordwrap turned on. If resizing the control causes the number of lines to decrease, and the caret is positioned in the last line of text, pressing a key will result in a UAE.

RESOLUTION To correct the error, the edit control must perform some action that updates the caret position. For example, the following line of code corrects the problem and should be used after the control has been resized: SendMessage(hEdit, EM_SETSEL, 0, MAKELONG(32767, 32767)); This has the side-effect that the caret is forced to the last character in the control.

More Information: When the edit control is resized, the number of lines decreases; however, Windows does not update the line position of the caret. If the caret is on the last line, the line number of the caret’s position will be greater than the number of lines in the edit control. When another character is pressed, Windows performs some internal maintenance for line information and uses (number of lines - caret line), which in this case is negative. In the end, this negative number causes Windows to access memory outside of an array boundary. Using EM_SETSEL forces Windows to update the internal position of the caret. The value 32767, used for the caret position, indicates the “last character” in the control. Because the start and end positions of the EM_SETSEL message are the same, the caret stays in the same position. Any other caret-updating action on the edit control will also correct the error.

Additional reference words: 3.00 KBCategory: KBSubcategory: UsrCtlEdit Copyright Microsoft Corporation 1993.