Multiline Edit Control Wraps Text Different than DrawText

Last reviewed: November 2, 1995
Article ID: Q67722
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) versions 3.0 and 3.1
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.5 and 3.51
        - Microsoft Windows 95 version 4.0
    

SUMMARY

Multiline edit controls will not wrap text in the same manner as the DrawText() function. This can be a problem when an application displays text that has been in an edit control because the text may wrap in a different location.

It is possible to obtain the text from the edit control and display it statically in a window with the same line breaks. To do this, the application must retrieve each line of text separately. This can be accomplished by sending the EM_GETLINE message to the control and displaying the retrieved text with the TextOut() function.

MORE INFORMATION

The following is a brief code fragment that demonstrates how to obtain the text of a multiline edit control line by line:

   ... /* other code */

   char  buf[80];         // Buffer for line storage
   HDC   hDC;             // Temporary display context
   HFONT hFont;           // Temporary font storage
   int   iNumEditLines;   // How much text
   TEXTMETRIC tm;         // Text metrics

   // Get number of lines in the edit control
   iNumEditLines = SendMessage(hEditCtl, EM_GETLINECOUNT, 0, 0L);

   hDC = GetDC(hWnd);

   // Get font currently selected into the control
   hFont = SendMessage(hEditCtl, WM_GETFONT, 0, 0L);

   // If it is not the system font, then select it into DC
   if (hFont)
      SelectObject(hDC, hFont);

   GetTextMetrics(hDC, &tm);
   iLine = 0;

   while (iNumEditLines--)
      {
      // First word of buffer contains max number of characters
      // to be copied
      buf[0] = 80;

      // Get the current line of text
      nCount = SendMessage(hEditCtl, EM_GETLINE, iLine, (LONG)buf);
      TextOut(hDC, x, y, buf, nCount);  // Output text to device
      y += tm.tmHeight;
      iLine++;
      }

   ReleaseDC(hWnd, hDC);
   ... /* other code */

The execution time of this code could be reduced by using the ExtTextOut() function instead of TextOut().


Additional reference words: 3.00 3.10 3.50 4.00 95
KBCategory: kbui
KBSubcategory: UsrCtl


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: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.