我正在使用 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
结构,更改使用的文本颜色。
令人困惑的是 DTTOPS 结构允许我指定一种颜色:
typedef 结构 _DTTOPTS
{
DWORD dwSize; // 结构体的大小
DWORD dwFlags; // 指定了哪些选项
COLORREF crText; // 用于文本填充的颜色
COLORREF crBorder; // 用于文本轮廓的颜色
COLORREF crShadow; // 用于文本阴影的颜色
...
与 DTT_TEXTCOLOR 标志一起指示我正在使用该成员:
#define DTT_TEXTCOLOR (1UL << 0) // crText 已指定
我想要完成的事情已记录在案,但它无法正常工作。显然我做错了什么。
使用 DrawThemeTextEx?
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:
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?
发布评论
评论(1)
crText
成员是一个ColorRef
。 MSDN 说高位字节“必须为零”。The
crText
member is aColorRef
. MSDN says the high-order byte "must be zero."