| Multiline Edit Control Wraps Text Different than DrawTextLast reviewed: November 2, 1995Article ID: Q67722 | 
| The information in this article applies to: 
 
 SUMMARYMultiline 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 INFORMATIONThe 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 
 © 1998 Microsoft Corporation. All rights reserved. Terms of Use. |