Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

DrawThemeText function

Draws text using the color and font defined by the visual style.

Syntax


HRESULT DrawThemeText(
  _In_  HTHEME hTheme,
  _In_  HDC hdc,
  _In_  int iPartId,
  _In_  int iStateId,
  _In_  LPCWSTR pszText,
  _In_  int iCharCount,
  _In_  DWORD dwTextFlags,
  _In_  DWORD dwTextFlags2,
  _In_  LPCRECT pRect
);

Parameters

hTheme [in]

Type: HTHEME

Handle to a window's theme data. Use OpenThemeData to create an HTHEME.

hdc [in]

Type: HDC

HDC to use for drawing.

iPartId [in]

Type: int

The control part that has the desired text appearance. See Parts and States. If this value is 0, the text is drawn in the default font, or a font selected into the device context.

iStateId [in]

Type: int

The control state that has the desired text appearance. See Parts and States.

pszText [in]

Type: LPCWSTR

Pointer to a string that contains the text to draw.

iCharCount [in]

Type: int

Value of type int that contains the number of characters to draw. If the parameter is set to -1, all the characters in the string are drawn.

dwTextFlags [in]

Type: DWORD

DWORD that contains one or more values that specify the string's formatting. See Format Values for possible parameter values.

Note  DrawThemeText does not support DT_CALCRECT. However, DrawThemeTextEx does support DT_CALCRECT.

dwTextFlags2 [in]

Type: DWORD

Not used. Set to zero.

pRect [in]

Type: LPCRECT

Pointer to a RECT structure that contains the rectangle, in logical coordinates, in which the text is to be drawn. It is recommended to use pExtentRect from GetThemeTextExtent to retrieve the correct coordinates.

Return value

Type: HRESULT

If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

The function always uses the themed font for the specified part and state if one is defined. Otherwise it uses the font currently selected into the device context. To find out if a themed font is defined, you can call GetThemeFont or GetThemePropertyOrigin with TMT_FONT as the property identifier.

Examples

DrawThemeText uses parameters similar to the Win32 DrawText function, but with a few differences. One of the most notable is support for wide-character strings. Therefore, non-wide strings must be converted to wide strings, as in the following example.

Security Warning:  Using MultiByteToWideChar incorrectly can compromise the security of your application. Ensure that when creating wide-character buffers they are large enough to accommodate the size of the string in wide characters, not in bytes.


INT cchText = GetWindowTextLength(_hwnd);
if (cchText > 0)
{
    TCHAR *pszText = new TCHAR[cchText+1];
    if (pszText)
    {
        if (GetWindowText(_hwnd, pszText, cchText+1))
        {
            int widelen = MultiByteToWideChar(CP_ACP, 0, reinterpret_cast<LPCSTR>(pszText), 
                    cchText+1, NULL, 0);
            WCHAR *pszWideText = new WCHAR[widelen+1];
            MultiByteToWideChar(CP_ACP, 0, reinterpret_cast<LPCSTR>(pszText), cchText, 
                    pszWideText, widelen);

            SetBkMode(hdcPaint, TRANSPARENT);
            DrawThemeText(_hTheme,
                    hdcPaint,
                    BP_PUSHBUTTON,
                    _iStateId,
                    pszWideText,
                    cchText,
                    DT_CENTER | DT_VCENTER | DT_SINGLELINE,
                    NULL,
                    &rcContent);

            delete [] pszWideText;
        }

        delete [] pszText;
    }
}


Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

Uxtheme.h

Library

UxTheme.lib

DLL

UxTheme.dll

See also

Property Identifiers

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.