Share via


Formatting Text (Windows CE 5.0)

Send Feedback

Windows CE provides a complete set of functions to format and draw text in an application client area and on a page of printer paper.

An application can use the SetTextAlign function to specify how the operating system (OS) should position the characters in a string of text when the application calls one of the drawing functions. You can use this function to control the position of headings, page numbers, callouts, and so on. The OS positions a string of text by aligning a reference point on an imaginary rectangle that surrounds the string with the current cursor position or with a point that you pass as an argument to one of the text drawing functions. SetTextAlign allows the application to specify the location of this reference point by using the fmode parameter. The following table shows the possible reference point locations.

Horizontal alignment flag Vertical alignment flag Description
TA_LEFT TA_BOTTOM The reference point is located at the bottom-left corner of the rectangle.
TA_LEFT TA_BASELINE The reference point is located at the intersection of the character-cell base line and the left edge of the rectangle.
TA_LEFT TA_TOP The reference point is located at the top-left corner of the rectangle.
TA_CENTER TA_BOTTOM The reference point is located at the center of the bottom of the rectangle.
TA_CENTER TA_BASELINE The reference point is located at the intersection of the character-cell base line and the center of the rectangle.
TA_CENTER TA_TOP The reference point is located at the center of the top of the rectangle.
TA_RIGHT TA_BOTTOM The reference point is located at the bottom-right corner of the rectangle.
TA_RIGHT TA_BASELINE The reference point is located at the intersection of the character-cell base line and the right edge of the rectangle.
TA_RIGHT TA_TOP The reference point is located at the top-right corner of the rectangle.

The default text alignment for a device context is the upper-left corner of the imaginary rectangle that surrounds the text. An application can retrieve the current text-alignment setting for any device context by calling the GetTextAlign function.

The default text color for a display device context is black; the default background color is white; and the default background mode is OPAQUE. Call the SetTextColor and GetTextColor functions to respectively set and retrieve the color of text drawn in the client area of a window or printed by a color printer. Call the SetBkColor and GetBkColor functions to respectively set or retrieve the background color. Call the SetBkMode and the GetBkMode functions to respectively set or retrieve the background mode. The background mode specifies the logical method for combining the selected background color with the current video display colors.

An application needs to retrieve character-width data when the application performs tasks such as fitting strings of text to page or column widths. An application can use the GetCharWidth32 function to retrieve the advance width for individual characters or symbols in a string of text. The advance width is the distance that the cursor on a display or the print head on a printer must advance before printing the next character in a string of text. GetCharWidth32 returns the advance width as an integer value.

In addition to retrieving character-width data for individual characters, applications also need to compute the width and height of entire strings. You can call the GetTextExtentPoint32 function to compute the advance width and height of a string of text.

You can call the GetTextMetrics function to retrieve the logical dimensions of a font. You can call the GetDeviceCaps function to determine the dimensions of an output device. GetDeviceCaps returns both physical and logical dimensions.

A logical inch is a measure that the OS uses to present legible fonts on the screen that is approximately 30 to 40 percent larger than a physical inch. Using logical inches precludes an exact match between the output of the screen and printer. The text on a screen is not simply a scaled version of the text that appears on the page, particularly if you incorporate graphics into the text.

See Also

Fonts Application Development

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.