gpt4 book ai didi

delphi - 如何更改主题DrawThemeTextEx字体颜色?

转载 作者:行者123 更新时间:2023-12-03 14:53:13 28 4
gpt4 key购买 nike

我正在使用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;

不幸的是,文本颜色总是黑色,而不是我的代码指定的明亮的石灰绿色:

enter image description here

可以更改 selecting the new font into the device context 使用的字体 ,即:

   SelectObject(dc, font.Handle);

但都没有SetTextColor ,也不设置 DTTOPScrTextDTT_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 绘制文本时如何指定文本颜色

最佳答案

crText 成员是一个 ColorRefMSDN says高位字节“必须为零。”

关于delphi - 如何更改主题DrawThemeTextEx字体颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6741512/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com