Microsoft KB Archive/67722

-

{| 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
 * width="100%"|

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.
 * }

-

Last reviewed: November 2, 1995

© 1998 Microsoft Corporation. All rights reserved. Terms of Use.