如何测量树视图项中文本的可用宽度? [英] How do I measure the width available for text in a tree view item?

查看:28
本文介绍了如何测量树视图项中文本的可用宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标准的 Win32 树视图控件.我将文件名放入根节点.为了避免要求用户使用水平滚动条,我想使用 PathCompactPath 缩短文本以适应控件上的可用空间.

I have a standard Win32 tree view control. I'm putting a file name into the root node. To avoid asking the user to use a horizontal scroll bar I would like to shorten the text using PathCompactPath to fit in the space available on the control.

因此,为了做到这一点,我需要测量上面屏幕截图中标记的距离.我知道 TVM_GETITEMRECT 但它返回一个包含图标占用空间的矩形.

So, in order to do this I need to measure the distance marked in the screenshot above. I know about TVM_GETITEMRECT but it returns a rect that includes the space taken up by the icon.

那么,我怎样才能获得我需要的指标?甚至有可能这样做吗?

So, how can I obtain the metric I need? Is it even possible to do so?

推荐答案

您是否为 wParam 参数指定了 TRUEFALSE代码>TVM_GETITEMRECT?获取节点的文本矩形应该是 TRUE.完成后,您可以从 TreeView 的客户端宽度中减去矩形的左侧像素值以获得您要查找的宽度.

Are you specifying TRUE or FALSE for the wParam parameter of TVM_GETITEMRECT? It should be TRUE to get the node's text rectangle. Once you have that, you can subtract the rectangles's left pixel value from the client width of the TreeView to get the width you are looking for.

这篇关于如何测量树视图项中文本的可用宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆