Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change theme DrawThemeTextEx font color?

i am using DrawThemeTextEx to draw text. i am trying to draw it in a particular color using the crText COLORREF member of DTTOPS 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 text color always comes out black, rather than the bright lime green color my code is specifying:

enter image description here

i can alter the font that is used by selecting the new font into the device context, i.e.:

   SelectObject(dc, font.Handle);

but neither SetTextColor, nor setting the crText and DTT_TEXTCOLOR options of the DTTOPS structure, alter the text color used.

What's confusing is that the DTTOPS structure allows me to specify a 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 i'm using that member:

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

What i want to accomplish is documented, but it's not working right. Obviously i'm doing something wrong.

How do i specify the text color when drawing text using DrawThemeTextEx?

like image 628
Ian Boyd Avatar asked Jul 19 '11 02:07

Ian Boyd


People also ask

How do you change the color of your text?

Go to Format > Font > Font. + D to open the Font dialog box. Select the arrow next to Font color, and then choose a color. Select Default and then select Yes to apply the change to all new documents based on the template.

How do you color letters?

Select the text that you want to change. On the Home tab, in the Font group, choose the arrow next to Font Color, and then select a color.


1 Answers

The crText member is a ColorRef. MSDN says the high-order byte "must be zero."

like image 76
Rob Kennedy Avatar answered Sep 28 '22 10:09

Rob Kennedy