我正在使用DrawThemeTextEx来绘制文字。我试图使用crText
结构的DTTOPS
COLORREF成员以特定颜色绘制它:
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;
不幸的是,文字颜色总是黑色,而不是我的代码指定的鲜艳的柠檬绿色:
我可以改变selecting the new font into the device context使用的字体,即:
SelectObject(dc, font.Handle);
但SetTextColor
既不设置DTTOPS
结构的crText
和DTT_TEXTCOLOR
选项,也会改变使用的文字颜色。
令人困惑的是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 ...
以及DTT_TEXTCOLOR标志表示我正在使用该成员:
#define DTT_TEXTCOLOR (1UL << 0) // crText has been specified
我想要完成 的记录,但它无法正常工作。显然我做错了。
使用DrawThemeTextEx绘制文字时,如何指定文字颜色?