3.00 3.10
WINDOWS
kbprg kbfile
The information in this article applies to:
- Microsoft Windows Software Development Kit (SDK) for Windows
versions 3.0 and 3.1
SUMMARY
EXPEDIT is a file in the Microsoft Software Library that demonstrates
changing the size of an edit control in response to an EN_UPDATE message.
In the sample, when the typed text reaches the end of a line, the edit
control expands to allow the user to continue typing on a new line.
Download EXPEDIT.EXE, a self-extracting file, from the Microsoft Software
Library (MSL) on the following services:
MORE INFORMATION
Windows sends the EN_UPDATE notification message to the parent of the edit
control whenever the contents of the edit control have been altered, but
before the display is updated. The notification is sent to the parent
window as the HIWORD of the lParam parameter of a WM_COMMAND message. The
ID of the control is in the wParam.
Therefore, for an application to determine when it is necessary to change
the size of the edit control, it must handle the WM_COMMAND case in which
the wParam is the ID of the control and the HIWORD of the lParam is
EN_UPDATE. When EXPEDIT receives an EN_UPDATE notification message, it
performs the following eight actions:
- Sends an EM_FMTLINES message to the edit control (wParam = 1). When
the control processes this message, it modifies its buffer to have
the character sequence carriage return-carriage return-linefeed
(CR-CR-LF) at the end of each line.
- Retrieves the length of the edit control's buffer.
- Passes a handle to the (nonempty) buffer of the DrawText() function,
which calculates the size of the rectangle required to hold all the
text.
- Adjusts the text height returned by DrawText because DrawText
interprets the CR-CR-LF sequence at the end of each buffer line as
two lines instead of one.
- Compares the right edge of the rectangle returned from DrawText with
the "limit." DrawText will extend the right edge of the rectangle
if the text is too long. If the right edge of the last line exceeds
the limit, then the edit control needs an additional line. EXPEDIT
performs all the obvious limit checks.
- If the height has not changed, then it is not necessary to change
the size of the edit control, and EXPEDIT returns. Otherwise,
the size of the edit control must be changed.
- Updates the size of the edit control with MoveWindow() and
UpdateWindow().
- Returns FALSE so that the Dialog Manager will not do anything when
it receives the EN_UPDATE message.
NOTE: The key idea of this implementation is to "predict" whether the next
character will fit in the edit control; if it will not, then add a new line
to the control so that the character will fit. This prediction is
accomplished by subtracting the width of "W" from the edge of the edit
control's rectangle to get the limit.