HOWTO: Determine the Visible Area of a Multiline Edit Control
ID: Q88387
|
The information in this article applies to:
-
Microsoft Win32 Software Development Kit (SDK)
-
Microsoft Windows Software Development Kit (SDK) 3.1
-
Microsoft Windows 2000
SUMMARY
The multiline edit control provided with Microsoft Windows versions
3.0 and 3.1 does not provide a mechanism that allows an application to
determine the currently visible lines of text. This article outlines
an algorithm to provide that functionality.
MORE INFORMATION
The general idea is to determine the first and last visible lines and
obtain the text of those lines from the edit control. The following
steps detail this process:
- A Windows-3.1-based application can use the newly available
message, EM_GETFIRSTVISIBLELINE, to determine the topmost visible
line.
A Windows-3.0-based application can use a technique described in the
following Microsoft Knowledge Base article to determine the line
number of the first visible line:
Q68572
Caret Position & Line Numbers in Multiline Edit Controls
- Obtain the edit control's formatting rectangle using EM_GETRECT.
Determine the rectangle's height using this formula:
nFmtRectHeight = rect.bottom - rect.top;
- Obtain the line spacing of the font used by the edit control to
display the text. Use the WM_GETFONT message to determine the font
used by the edit control. Select this font into a display context
and use the GetTextMetrics function. The tmHeight field of the
resulting TEXTMETRIC structure is the line spacing.
- Divide the formatting rectangle's height (step 2) with the line
spacing (step 3) to determine the number of lines. Compute the line
number of the last visible line based on the first visible line
(step 1) and the number of visible lines.
- Use EM_GETLINE for each line number from the first visible line to
the last visible line to determine the visible lines of text.
Remember that the last visible line may not necessarily be at the
bottom of the edit control (the control may only be half full). To
detect this case, use EM_GETLINECOUNT to know the last line and
compare its number with the last visible line. If the last line
number is less than the last visible line, your application should
use EM_GETLINE only on lines between the first and the last line.
Additional query words:
Keywords : kbCtrl kbEditCtrl kbNTOS kbWinOS2000 kbSDKWin32 kbGrpUser kbWinOS
Version : WINDOWS:3.1
Platform : WINDOWS
Issue type : kbhowto