Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function draws formatted text in the specified rectangle. DrawTextformats the text according to the specified format method.

Syntax

int DrawText(
  HDC 
hDC, 
  LPCTSTR 
lpString, 
  int 
nCount, 
  LPRECT 
lpRect, 
  UNIT 
uFormat
);

Parameters

hDC

[in] Handle to the device context.

lpString

[in] Long pointer to the string that you want to draw. If the nCountparameter is –1, you must specify a null-terminated string.

nCount

[in] Integer that specifies the number of characters in the string. If nCountis –1, DrawTextassumes that the lpStringparameter is a pointer to a null-terminated string and computes the character count automatically.

lpRect

[in] Long pointer to a RECTstructure that contains the rectangle, in logical coordinates, in which you want to format the text.

uFormat

[in] Unsigned integer that specifies the method of formatting the text. The following table shows the possible values that you can combine to create a value for this parameter.

Value Description

DT_BOTTOM

Justifies the text to the bottom of the rectangle. You must combine this value with DT_SINGLELINE.

DT_CALCRECT

Determines the width and height of the rectangle. If the rectangle includes multiple lines of text, DrawTextuses the width of the rectangle pointed to by the lpRectparameter and extends the base of the rectangle to bound the last line of text. If the rectangle includes only one line of text, DrawTextmodifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawTextreturns the height of the formatted text but does not draw the text.

Before calling DrawText, an application must set the rightand bottommembers of the RECTstructure pointed to by lpRect. These members are updated with the call to DrawText.

DT_CENTER

Centers text horizontally in the rectangle.

DT_END_ELLIPSIS

Truncates a text string that is wider than the display rectangle and adds an ellipsis to indicate the truncation.

DT_EXPANDTABS

Expands tab characters. The default number of characters per tab is eight.

DT_INTERNAL

Uses the system font to calculate text metrics.

DT_LEFT

Aligns text to the left.

DT_NOCLIP

Draws without clipping. DrawTextis somewhat faster when DT_NOCLIP is used.

DT_NOPREFIX

Turns off processing of prefix characters. Normally, DrawTextinterprets the mnemonic-prefix character & as a directive to underscore the character that follows, and the mnemonic-prefix characters && as a directive to print a single &. By specifying DT_NOPREFIX, this processing is turned off.

DT_RIGHT

Aligns text to the right.

DT_RTLREADING

Layout in right-to-left reading order for bi-directional text when the font selected into the hdc is a Hebrew or Arabic font. The default reading order for all text is left-to-right.

DT_SINGLELINE

Displays text on a single line only. Carriage returns and linefeeds do not break the line.

DT_TABSTOP

Sets tab stops. Bits 8–15, which form the high-order byte of the low-order word, of the uFormatparameter specify the number of characters for each tab. The default number of characters per tab is eight. You cannot use the DT_CALCRECT, DT_EXTERNALLEADING, DT_INTERNAL, DT_NOCLIP, and DT_NOPREFIX values with the DT_TABSTOP value.

DT_TOP

Top-justifies text. You must combine this value with DT_SINGLELINE.

DT_VCENTER

Centers text vertically. You must combine this value with DT_SINGLELINE.

DT_WORD_ELLIPSIS

Truncates any word that does not fit in the display rectangle and adds an ellipsis.

DT_WORDBREAK

Breaks words. DrawTextautomatically breaks lines between words if a word would extend past the edge of the rectangle specified by the lpRectparameter. A carriage return-linefeed sequence also breaks the line.

Return Value

The height of the text indicates success. Zero indicates failure. To get extended error information, call GetLastError.

Remarks

The DrawTextfunction uses the selected font, text color, and background color for the device context to draw the text. Unless you specify the DT_NOCLIP value, DrawTextclips the text so that it does not appear outside the specified rectangle. DrawTextassumes that all formatting has multiple lines unless you specify the DT_SINGLELINE format.

If the selected font is too large for the specified rectangle, the DrawTextfunction does not attempt to substitute a smaller font.

For Windows CE 2.10 and later, line breaking is supported for the Chinese, Korean, and Japanese languages.

Requirements

Header windows.h
Library coredll.lib
Windows Embedded CE Windows CE 1.0 and later
Windows Mobile Pocket PC for Windows Mobile Version 5.0 and later, Smartphone for Windows Mobile Version 5.0 and later

See Also

Reference

ExtTextOut

Other Resources

RECT