Function Reference


_WinAPI_DrawText

Draws formatted text in the specified rectangle

#include <WinAPIGdiDC.au3>
_WinAPI_DrawText ( $hDC, $sText, ByRef $tRECT, $iFlags )

Parameters

$hDC Identifies the device context
$sText The string to be drawn
$tRECT $tagRECT structure that contains the rectangle for the text
$iFlags Specifies the method of formatting the text:
$DT_BOTTOM - Justifies the text to the bottom of the rectangle
$DT_CALCRECT - Determines the width and height of the rectangle
$DT_CENTER - Centers text horizontally in the rectangle
$DT_EDITCONTROL - Duplicates the text-displaying characteristics of a multiline edit control
$DT_END_ELLIPSIS - Replaces part of the given string with ellipses if necessary
$DT_EXPANDTABS - Expands tab characters
$DT_EXTERNALLEADING - Includes the font external leading in line height
$DT_HIDEPREFIX - Ignores the ampersand (&) prefix character in the text.
The letter that follows will not be underlined, but other mnemonic-prefix characters are still processed.
$DT_INTERNAL - Uses the system font to calculate text metrics
$DT_LEFT - Aligns text to the left
$DT_MODIFYSTRING - Modifies the given string to match the displayed text
$DT_NOCLIP - Draws without clipping
$DT_NOFULLWIDTHCHARBREAK - Prevents a line break at a DBCS (double-wide character string), so that the line breaking rule is equivalent to SBCS strings.
For example, this can be used in Korean windows, for more readability of icon labels.
This value has no effect unless $DT_WORDBREAK is specified
$DT_NOPREFIX - Turns off processing of prefix characters
$DT_PATH_ELLIPSIS - For displayed text, replaces characters in the middle of the string with ellipses so that the result fits in the specified rectangle.
If the string contains backslash (\) characters, $DT_PATH_ELLIPSIS preserves as much as possible of the text after the last backslash.
The string is not modified unless the $DT_MODIFYSTRING flag is specified
$DT_PREFIXONLY - Draws only an underline at the position of the character following the ampersand (&) prefix character.
Does not draw any other characters in the string
$DT_RIGHT - Aligns text to the right
$DT_RTLREADING - Layout in right to left reading order for bi-directional text
$DT_SINGLELINE - Displays text on a single line only
$DT_TABSTOP - Sets tab stops. Bits 15-8 of $iFlags specify the number of characters for each tab
$DT_TOP - Top-justifies text (single line only)
$DT_VCENTER - Centers text vertically (single line only)
$DT_WORDBREAK - Breaks words
$DT_WORD_ELLIPSIS - Truncates any word that does not fit in the rectangle and adds ellipses

Return Value

Success: The height of the text
Failure: 0

Remarks

The DrawText function uses the device context's selected font, text color, and background color to draw the text.
Unless the $DT_NOCLIP format is used, DrawText clips the text so that it does not appear outside the specified rectangle.
All formatting is assumed to have multiple lines unless the $DT_SINGLELINE format is specified.
If the selected font is too large, DrawText does not attempt to substitute a smaller font.

Above constants require #include <WindowsConstants.au3>

Related

$tagRECT, _WinAPI_GetBkMode, _WinAPI_SetBkMode

See Also

Search DrawText in MSDN Library.

Example

#include <FontConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPIGdiDC.au3>
#include <WinAPIHObj.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>

Global $g_tRECT, $g_hFont, $g_hOldFont, $g_hDC

HotKeySet("{ESC}", "_Exit")

$g_tRECT = DllStructCreate($tagRect)
DllStructSetData($g_tRECT, "Left", 5)
DllStructSetData($g_tRECT, "Top", 5)
DllStructSetData($g_tRECT, "Right", 250)
DllStructSetData($g_tRECT, "Bottom", 50)

$g_hDC = _WinAPI_GetDC(0)
$g_hFont = _WinAPI_CreateFont(50, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, _
                $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial')
$g_hOldFont = _WinAPI_SelectObject($g_hDC, $g_hFont)

_WinAPI_SetTextColor($g_hDC, 0x0000FF)
_WinAPI_SetBkColor($g_hDC, 0x000000)
; comment next line to get black background instead of transparent one
_WinAPI_SetBkMode($g_hDC, $TRANSPARENT)

While 1
        _WinAPI_DrawText($g_hDC, "Hello world!", $g_tRECT, $DT_CENTER)
        Sleep(100)
WEnd

Func _Exit()
        _WinAPI_SelectObject($g_hDC, $g_hOldFont)
        _WinAPI_DeleteObject($g_hFont)
        _WinAPI_ReleaseDC(0, $g_hDC)
        _WinAPI_InvalidateRect(0, 0)
        $g_tRECT = 0
        Exit
EndFunc   ;==>_Exit