The DrawText function formats and draws text within a given rectangle in the client area. This function provides simple text processing that most applications can use to display text. DrawText output is similar to the output generated by a terminal, except it uses the selected font and can clip the text if it extends outside a given rectangle. DrawText provides many different formatting styles. For a list of the text formatting styles, see the description of the DrawText function in the Microsoft Windows Programmer's Reference, Volume 2.
The DrawText function uses the currently selected font, so applications can draw formatted text in a font other than the system font.
DrawText does not hyphenate, and although it can left align, right align, or center text, it cannot combine alignment styles. In other words, it cannot align to both the left and right.
DrawText recognizes a number of control characters and carries out special
actions when it encounters them. The control characters and their respective
actions are as follows:
Windows character | Action |
Carriage return (13) | Interpreted as a line-break character. The text is immediately broken and continued on the next line down in the rectangle. |
Linefeed (10) | Interpreted as a line-break character. The text is immediately broken and continued on the next line down in the rectangle. |
A carriage return–linefeed character combination is interpreted as a single line-break character. | |
Space (32) | Interpreted as a wordwrap character if the DT_WORDBREAK style is given. If the text is too long to fit on the current line in the formatting rectangle, the line is broken at the wordwrap character that is closest to the end of the line. |
Tab (9) | Expanded into a given number of spaces if the DT_EXPANDTABS style is given. The number of spaces depends on which tab-stop value is given with the DT_TABSTOP style. The default value is eight. |