SAMPLE: Changing Size of an Edit Control

Last reviewed: July 23, 1997
Article ID: Q80553
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:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download EXPEDIT.EXE (size: 29990 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get EXPEDIT.EXE (size: 29990 bytes) 
    

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:

  1. 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.

  2. Retrieves the length of the edit control's buffer.

  3. Passes a handle to the (nonempty) buffer of the DrawText() function, which calculates the size of the rectangle required to hold all the text.

  4. 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.

  5. 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.

  6. 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.

  7. Updates the size of the edit control with MoveWindow() and UpdateWindow().

  8. 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 reference words: 3.00 3.10 softlib EXPEDIT.EXE
KBCategory: kbprg kbfile
KBSubcategory: UsrCtl
Keywords : kb16bitonly UsrCtl kbfile kbprg
Version : 3.00 3.10
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 23, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.