我将使用DrawThemeTextEx来绘制文本。我尝试使用
DTTOPS
结构的crText
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;
不幸的是,文本颜色始终为黑色,而不是我所指定的明亮青柠绿色:
SelectObject(dc, font.Handle);
但是既不使用SetTextColor
,也不设置DTTOPS
结构体的crText
和DTT_TEXTCOLOR
选项,都不能改变所使用的文本颜色。
令人困惑的是,DTTOPS结构体允许我指定一种颜色:
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绘制文本时,如何指定文本颜色?