ExpEdit.exe Changes Size of an Edit Control
ID: Q80553
|
The information in this article applies to:
-
Microsoft Windows Software Development Kit (SDK) 3.1
SUMMARY
ExpEdit.exe is a sample file that demonstrates how to change 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.
MORE INFORMATIONThe following files are available for download from the Microsoft
Download Center. Click the file names below to download the files:
ExpEdit.exe
For more information about how to download files from the Microsoft
Download Center, please visit the Download Center at the following Web
address
http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center.
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.
Additional query words:
Keywords : kbfile kbsample kb16bitonly kbCtrl kbEditCtrl kbSDKPlatform kbGrpUser kbDSupport
Version : WINDOWS:3.1
Platform : WINDOWS
Issue type : kbinfo
|