如何获取使用windows 7在treeview控件中绘制父节点的图像?

发布于 2024-11-05 07:09:15 字数 2095 浏览 0 评论 0原文

我正在使用混合两个窗口控件(列表视图和树视图)的自定义控件。在某些时候,我需要绘制使用 Windows 7(启用主题)的图像来识别父节点,我使用 DrawThemeBackground 函数TVP_GLYPH 部分和 GLPS_CLOSED 状态(我尝试了与 TREEVIEW 类相关的所有部分和状态,但没有成功),但结果图像始终是 (+) 或(-)。

此图像显示问题

在此处输入图像描述

我想绘制箭头图像(在黑色圆圈)而不是 (+) 符号(橙色圆圈内部)。

这是我用来绘制图像的示例代码。

uses
  UxTheme;

procedure TForm40.Button1Click(Sender: TObject);
var
  iPartId : integer;
  iStateId: integer;
  hTheme  : THandle;
begin
  hTheme  := OpenThemeData(Handle, VSCLASS_TREEVIEW);

  iPartId := TVP_GLYPH;
  iStateId:= GLPS_CLOSED;          
  //iPartId := TVP_TREEITEM;
  //iStateId:= TREIS_NORMAL;
  if hTheme <> 0 then
    try
      
      //if (IsThemeBackgroundPartiallyTransparent(hTheme, iPartId, iStateId)) then
      //    DrawThemeParentBackground(Handle, PaintBox1.Canvas.Handle, nil);
      
      DrawThemeBackground(hTheme, PaintBox1.Canvas.Handle, iPartId, iStateId, Rect(0, 0, 31, 31), nil);
    finally
      CloseThemeData(hTheme);
    end;
end;

我检查了一些工具,例如 应用程序Andreas Rejbrand这个也是如此,但我找不到我想要的图像。

我的问题是:如何获得箭头图像?

更新

感谢针对Stigma发布的答案,我找到了其他资源Explorer::Treeview 类的各部分和状态的值。

I'm working in a custom control which mix two windows controls (listview and treeview). In some point, I need to draw the image which uses windows 7 (with themes enabled) to identify the parent nodes, I'm using the DrawThemeBackground function with the TVP_GLYPH part and the GLPS_CLOSED state (I tried with all the parts and states related to the TREEVIEW class without luck), but the result image always is the old (+) or (-).

This image show the issue

enter image description here

I want to draw the Arrow image (inside of black circle) instead of the (+) sign (inside of orange circle).

This is the sample code which I use to draw the image.

uses
  UxTheme;

procedure TForm40.Button1Click(Sender: TObject);
var
  iPartId : integer;
  iStateId: integer;
  hTheme  : THandle;
begin
  hTheme  := OpenThemeData(Handle, VSCLASS_TREEVIEW);

  iPartId := TVP_GLYPH;
  iStateId:= GLPS_CLOSED;          
  //iPartId := TVP_TREEITEM;
  //iStateId:= TREIS_NORMAL;
  if hTheme <> 0 then
    try
      
      //if (IsThemeBackgroundPartiallyTransparent(hTheme, iPartId, iStateId)) then
      //    DrawThemeParentBackground(Handle, PaintBox1.Canvas.Handle, nil);
      
      DrawThemeBackground(hTheme, PaintBox1.Canvas.Handle, iPartId, iStateId, Rect(0, 0, 31, 31), nil);
    finally
      CloseThemeData(hTheme);
    end;
end;

I check a couple of tools like the application made by Andreas Rejbrand and this too, but I can't find the image which I want.

My question is : how I can obtain the arrow image?

UPDATE

Thanks to the answer posted for Stigma I found additional resources to the values of the parts and states of the Explorer::Treeview class.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

零時差 2024-11-12 07:09:15

首先,对于普通的ListViewTreeView,只需调用SetWindowTheme 在其句柄上应用适当的样式。其 MSDN 页面的示例如下:

SetWindowTheme(hwndList, L"Explorer", NULL);

由于我们正在讨论自定义控件,因此我不太确定这是否适用于此处。但自从 SetWindowTheme< /a> 导致 WM_THEMECHANGED 消息发送到正确的窗口,这意味着您只需要对特定的窗口使用正确的 OpenThemeData 调用子主题。

我认为卢克的评论是正确的。您可能只需要传递“Explorer::Treeview”而不是普通样式。所以,除非多年没有接触过 Delphi/Pascal:

hTheme  := OpenThemeData(Handle, 'Explorer::Treeview');

First of all, in the case of an ordinary ListView or TreeView, one can simply call SetWindowTheme on its handle to apply the proper sort of styling. The example from its MSDN page is as follows:

SetWindowTheme(hwndList, L"Explorer", NULL);

Since we are talking about a custom control, I am not so sure that applies here however. But since SetWindowTheme causes the WM_THEMECHANGED message to be sent to the proper window, it implies that you will just need to use the proper OpenThemeData call for the specific sub theme.

I think Luke's comment is correct. You probably just need to pass 'Explorer::Treeview' rather than the plain style. So, barring years of not having touched Delphi/Pascal:

hTheme  := OpenThemeData(Handle, 'Explorer::Treeview');
未央 2024-11-12 07:09:15

您必须在绘制之前设置 SetWindowTheme(Handle, 'explorer', nil); 以确保 OpenThemeData 将使用新的资源管理器样式主题。当然,两个函数的窗口句柄必须相同。

You must set SetWindowTheme(Handle, 'explorer', nil); before painting to ensure that OpenThemeData will use new explorer style theme. Of course, window handle must be the same for both functions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文