如何获取使用windows 7在treeview控件中绘制父节点的图像?
我正在使用混合两个窗口控件(列表视图和树视图)的自定义控件。在某些时候,我需要绘制使用 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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,对于普通的
ListView
或TreeView
,只需调用SetWindowTheme
在其句柄上应用适当的样式。其 MSDN 页面的示例如下:由于我们正在讨论自定义控件,因此我不太确定这是否适用于此处。但自从
SetWindowTheme
< /a> 导致WM_THEMECHANGED
消息发送到正确的窗口,这意味着您只需要对特定的窗口使用正确的OpenThemeData
调用子主题。我认为卢克的评论是正确的。您可能只需要传递“Explorer::Treeview”而不是普通样式。所以,除非多年没有接触过 Delphi/Pascal:
First of all, in the case of an ordinary
ListView
orTreeView
, one can simply callSetWindowTheme
on its handle to apply the proper sort of styling. The example from its MSDN page is as follows:Since we are talking about a custom control, I am not so sure that applies here however. But since
SetWindowTheme
causes theWM_THEMECHANGED
message to be sent to the proper window, it implies that you will just need to use the properOpenThemeData
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:
您必须在绘制之前设置
SetWindowTheme(Handle, 'explorer', nil);
以确保OpenThemeData
将使用新的资源管理器样式主题。当然,两个函数的窗口句柄必须相同。You must set
SetWindowTheme(Handle, 'explorer', nil);
before painting to ensure thatOpenThemeData
will use new explorer style theme. Of course, window handle must be the same for both functions.