我正在使用DrawThemeTextEx来绘制文本。我正在尝试使用结构的crText
COLORREF 成员以特定颜色绘制它DTTOPS
:
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
,也不设置结构的crText
和DTT_TEXTCOLOR
选项DTTOPS
,改变使用的文本颜色。
令人困惑的是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绘制文本时如何指定文本颜色?