Discussion:
DrawThemeText always draws black text
(too old to reply)
Lars C. Hassing
2007-02-23 08:18:07 UTC
Permalink
The DrawThemeText documentation says:
"Draws text using the color and font defined by the visual style."

So I would expect a caption text in the default Windows XP blue theme
to be white with black shadow.
But it is black with black shadow.
If I use MXCS_INACTIVE the shadow correctly disappears but the text is
still black (not white (grey)).
The font, however, seems to be OK.

DrawThemeBackground (hTheme, hDC, WP_MAXCAPTION, MXCS_ACTIVE, &r,
NULL);
DrawThemeText (hTheme, hDC, WP_MAXCAPTION, MXCS_ACTIVE, L"My
Caption", -1, DT_VCENTER | DT_SINGLELINE | DT_LEFT | DT_NOPREFIX, 0,
&r);

I have tried SetTextColor with no luck.
/Lars
Christian ASTOR
2007-02-24 17:08:58 UTC
Permalink
Post by Lars C. Hassing
"Draws text using the color and font defined by the visual style."
So I would expect a caption text in the default Windows XP blue theme
to be white with black shadow.
But it is black with black shadow.
If I use MXCS_INACTIVE the shadow correctly disappears but the text is
still black (not white (grey)).
The font, however, seems to be OK.
DrawThemeBackground (hTheme, hDC, WP_MAXCAPTION, MXCS_ACTIVE, &r,
NULL);
DrawThemeText (hTheme, hDC, WP_MAXCAPTION, MXCS_ACTIVE, L"My
Caption", -1, DT_VCENTER | DT_SINGLELINE | DT_LEFT | DT_NOPREFIX, 0,
&r);
I have tried SetTextColor with no luck.
The color is GetSysColor(COLOR_CAPTIONTEXT)
that can be drawn with DrawThemeTextEx()(>XP) or DrawText() or part of
DrawNCPreview()
Lars C. Hassing
2007-02-27 23:27:27 UTC
Permalink
Post by Christian ASTOR
Post by Lars C. Hassing
"Draws text using the color and font defined by the visual style."
So I would expect a caption text in the default Windows XP blue theme
to be white with black shadow.
But it is black with black shadow.
If I use MXCS_INACTIVE the shadow correctly disappears but the text is
still black (not white (grey)).
The font, however, seems to be OK.
DrawThemeBackground (hTheme, hDC, WP_MAXCAPTION, MXCS_ACTIVE, &r,
NULL);
DrawThemeText (hTheme, hDC, WP_MAXCAPTION, MXCS_ACTIVE, L"My
Caption", -1, DT_VCENTER | DT_SINGLELINE | DT_LEFT | DT_NOPREFIX, 0,
&r);
I have tried SetTextColor with no luck.
The color is GetSysColor(COLOR_CAPTIONTEXT)
that can be drawn with DrawThemeTextEx()(>XP) or DrawText() or part of
DrawNCPreview()- Skjul tekst i anførselstegn -
Hi Christian,
yes, GetSysColor(COLOR_CAPTIONTEXT / COLOR_INACTIVECAPTIONTEXT)
seem to get me the right text colors, and
GetThemeColor(hTheme, PartId, StateId, TMT_TEXTSHADOWCOLOR, &Color);
gets me the correct shadow color, so I can then call DrawText() twice.

GetThemeColor(hTheme, PartId, StateId, TMT_TEXTCOLOR, &Color);
returns an error (0x80070490) ?

The font I can get from
GetThemeSysFont(hTheme,TMT_CAPTIONFONT, &lf);
whereas
GetThemeFont(hTheme, dc->m_hDC, PartId, StateId, TMT_GLYPHFONT, &lf);
also returns an error (0x80070490).
However, the font does not have the antialias bit set.

I really thought DrawThemeText was supposed to do all this work for
me ?
/Lars
H a r a l d C z e c h
2007-08-09 09:44:29 UTC
Permalink
Hi Lars (German?),
here is the solution for your problem. I was looking for a solution as well.
It's only a code fragment without error handling etc., but it shows what to
do:

HTHEME hTheme = OpenThemeData (hWnd, L"Window");
if (hTheme)
{
::DrawThemeBackground (hTheme, hdc, WP_CAPTION, CS_ACTIVE, &rc, NULL);

#define TXT L"Magnifier Settings" // L"Custom"


LOGFONTW lf; // GetThemeSysFont() returns a LOGFONTW, even if declared as
LOGFONT.
HRESULT hr = GetThemeSysFont (hTheme, TMT_CAPTIONFONT, (LOGFONT*) &lf);

// first choose the correct font for DrawThemeText()
HFONT titleFont = ::CreateFontIndirectW( &lf );
HFONT oldFont = (HFONT) ::SelectObject (hdc, titleFont);

DWORD nFlags = DT_CENTER | DT_WORD_ELLIPSIS | DT_SINGLELINE;

// now draw the theme text (generally black text width shadow), setting
another color before won't work
SetBkMode(hdc, TRANSPARENT);
DrawThemeText (hTheme, hdc, WP_CAPTION, CS_ACTIVE, TXT, -1, nFlags, 0, &rc)
;

// now draw the text in the correct color
COLORREF col = GetSysColor (COLOR_CAPTIONTEXT); // or
COLOR_INACTIVECAPTIONTEXT
::SetTextColor(hdc, col);
::DrawTextW (hdc, TXT, -1, &rc, nFlags);

// Cleanup
::SelectObject(hdc, oldFont);
DeleteObject (titleFont);
CloseThemeData (hTheme);
}

I hope it helps.
Harald
H a r a l d C z e c h
2007-08-15 14:38:53 UTC
Permalink
Hi Lars,
here is a complete code fragment for your problem (I was working on the same)
:

HTHEME hTheme = OpenThemeData (fWindow, L"Window");
if (hTheme)
{
::DrawThemeBackground (hTheme, hdc, WP_CAPTION, CS_ACTIVE, &rc, NULL);

#define TXT L"Magnifier Settings"


LOGFONTW lf; // GetThemeSysFont() returns a LOGFONTW, even if declared as
LOGFONT.
HRESULT hr = GetThemeSysFont (hTheme, TMT_CAPTIONFONT, (LOGFONT*) &lf);

// first choose the correct font for DrawThemeText()
HFONT titleFont = ::CreateFontIndirectW( &lf );
HFONT oldFont = (HFONT) ::SelectObject (hdc, titleFont);

DWORD nFlags = DT_CENTER | DT_WORD_ELLIPSIS | DT_SINGLELINE;

// now draw the theme text (generally black text width shadow), setting
another color before won't work
SetBkMode(hdc, TRANSPARENT);
DrawThemeText (hTheme, hdc, WP_CAPTION, CS_ACTIVE, TXT, -1, nFlags, 0, &rc)
;

// now draw the text in the correct color
COLORREF col = GetSysColor (COLOR_CAPTIONTEXT); // or
COLOR_INACTIVECAPTIONTEXT
::SetTextColor(hdc, col);
::DrawTextW (hdc, TXT, -1, &rc, nFlags);

// Cleanup
::SelectObject(hdc, oldFont);
DeleteObject (titleFont);
CloseThemeData (hTheme);
}

Cheers
Harald

Loading...