How to change the font color of DrawThemeTextEx?

I am using DrawThemeTextEx to draw text. I am trying to draw it in a specific color using the crText COLORREF element of the crText structure:

 procedure DrawThemeText(dc: HDC; text: WideString; font: TFont; pt: TPoint; foreColor: COLORREF); var R: TRect; dttOpts: TDttOpts; hOldFont: HFONT; oldColor: COLORREF; begin foreColor := $FF00FF00; //bright lime green font. R := Rect(pt.x, pt.y, $7fffffff, $7fffffff); ZeroMemory(@dttOpts, SizeOf(TDTTOpts)); dttOpts.dwSize := SizeOf(TDTTOpts); dttOpts.iGlowSize := 1; dttOpts.crText := foreColor; dttOpts.dwFlags := DTT_GLOWSIZE or DTT_TEXTCOLOR; hOldFont := SelectObject(dc, font.Handle); oldColor := SetTextColor(dc, foreColor); try hr := DrawThemeTextEx(ThemeServices.Theme[teWindow], DC, WP_CAPTION, CS_ACTIVE, PWideChar(Text), Length(Text), DT_LEFT or DT_TOP or DT_SINGLELINE or DT_NOPREFIX, R, dttOpts); finally SetTextColor(dc, oldColor); SelectObject(dc, hOldFont); end; 

Unfortunately, the color of the text is always highlighted in black, not the bright green, which my code indicates:

enter image description here

I can change the font that is used to select a new font in the device context , that is:

  SelectObject(dc, font.Handle); 

but not SetTextColor , without setting crText and DTT_TEXTCOLOR DTTOPS , change the text color used.

What confuses the fact that the DTAPS structure allows me to specify the color :

 typedef struct _DTTOPTS { DWORD dwSize; // size of the struct DWORD dwFlags; // which options have been specified COLORREF crText; // color to use for text fill COLORREF crBorder; // color to use for text outline COLORREF crShadow; // color to use for text shadow ... 

along with the DTT_TEXTCOLOR flag to indicate that I am using this element:

  #define DTT_TEXTCOLOR (1UL << 0) // crText has been specified 

What I want to accomplish is documented, but it does not work correctly. Obviously I'm doing something wrong.

How to specify text color when drawing text using DrawThemeTextEx ?

+6
source share
1 answer

The crText element is a ColorRef . MSDN says the high byte should be zero.

+6
source

Source: https://habr.com/ru/post/893032/


All Articles