gpt4 book ai didi

delphi - 使用DrawThemeBackground绘图时如何从右到左(RTL)方向绘制元素部分?

转载 作者:行者123 更新时间:2023-12-03 15:27:29 25 4
gpt4 key购买 nike

我正在尝试从右到左方向绘制 Explorer::Treeview 类的 ttGlyphClosed 元素(就像 BiDiMode 那样)为bdLeftToRight)。我有一个问题,我不知道如何使我的屏幕外位图透明。位图的背景始终为白色。

我使用以下代码来镜像图像:

procedure TForm5.FormPaint(Sender: TObject);
var
bm: TBitmap;
ARect: TRect;
Details: TThemedElementDetails;
begin
if ExplorerTreeviewhTheme = 0 then
ExplorerTreeviewhTheme := OpenThemeData(0, 'Explorer::Treeview');

ARect := Rect(20, 20, 40, 40);
Details := ThemeServices.GetElementDetails(ttGlyphClosed);
DrawThemeBackground(ExplorerTreeviewhTheme, Canvas.Handle,
Details.Part, Details.State, ARect, nil); //Ok

bm := TBitmap.Create;
try
bm.Width := 20;
bm.Height := 20;

ARect := Rect(00, 00, 20, 20);
DrawThemeBackground(ExplorerTreeviewhTheme, bm.Canvas.Handle,
Details.Part, Details.State, ARect, nil);

// rendered result has white background
Canvas.Draw(60, 10, bm);
// rendered result is mirrored but has also white background
StretchBlt(Canvas.Handle, 100, 10, -20, 20, bm.Canvas.Handle, 0, 0, 20, 20, SRCCOPY);
finally
bm.Free;
end;
end;

问题是如何镜像由 DrawThemeBackground 函数绘制的元素(用于 RTL 读取)或如何使用此函数进行 RTL(从右到左)渲染?

最佳答案

使用SetLayout,如 TLama 在他现已删除的答案中所示,在绘制之前切换 Canvas 的布局。

function SetLayout(hdc: HDC; dwLayout: DWORD): DWORD; stdcall;
external 'gdi32' name 'SetLayout';

const
LAYOUT_RTL = $00000001;

procedure TForm1.FormPaint(Sender: TObject);
var
ExplorerTreeviewhTheme: HTHEME;
Details: TThemedElementDetails;
ARect: TRect;
Size: TSize;
begin
ExplorerTreeviewhTheme := OpenThemeData(Handle, 'Explorer::Treeview');
Details := ThemeServices.GetElementDetails(ttGlyphClosed);
GetThemePartSize(ExplorerTreeviewhTheme, Canvas.Handle, Details.Part,
Details.State, nil, TS_DRAW, Size);

ARect := Rect(20, 30, 20 + Size.cx, 30 + Size.cy);

// normal layout
DrawThemeBackground(ExplorerTreeviewhTheme, Canvas.Handle,
Details.Part, Details.State, ARect, nil);

// switched layout
SetLayout(Canvas.Handle, LAYOUT_RTL);

// calculate the rectangle for RTL as if it's in LTR
OffsetRect(ARect, 0, Size.cy); // align to the bottom of the first image so that we can see
ARect.Left := ClientWidth - ARect.Left - Size.cx;
ARect.Right := ARect.Left + Size.cx;

DrawThemeBackground(ExplorerTreeviewhTheme, Canvas.Handle,
Details.Part, Details.State, ARect, nil);

// restore layout
SetLayout(Canvas.Handle, 0);
CloseThemeData(ExplorerTreeviewhTheme);
end;

输出: enter image description here

主题 api 正在以 16 像素的部分尺寸绘制 6 像素宽的三角形 (W7-aero)。由于您无法知道图像在零件中的位置,因此无法更好地对齐它。

关于delphi - 使用DrawThemeBackground绘图时如何从右到左(RTL)方向绘制元素部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13545636/

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