gpt4 book ai didi

c++ - 如何获得避免滚动条的 TreeView 控件的最小尺寸?

转载 作者:太空宇宙 更新时间:2023-11-04 13:37:36 25 4
gpt4 key购买 nike

我有一个对话框,里面有一个 TreeView ,我希望在展开或折叠树时自动调整对话框的大小,以避免出现滚动条或过多的空间。

为了做到这一点,我需要一些方法来找到 TreeView 的“所需”大小,即足够大以避免显示滚动条的最小尺寸。

有什么建议吗?

编辑:所以,我已经完成了一半。我可以通过计算可见项的数量并乘以 TreeView_GetItemHeight 来确定高度。我仍然不知道如何找到宽度,但是......

最佳答案

它不是很完美(似乎不可能让 TreeView_GetItemRect 水平包含整行直到文本末尾),但以下内容非常适合我禁用水平滚动的用例.

void Dialog::getDimensionTreeView(unsigned int id,
unsigned int &width, unsigned int &height) {
HWND item = GetDlgItem((HWND)_hwnd, id);
if(!item) {
width = 0;
height = 0;
return;
}

RECT area = { };
HTREEITEM node = TreeView_GetRoot(item);
do {
RECT rc;
LPRECT prc = &rc;
// Ideally this would use `fItemRect`=FALSE, but that seems
// to just return the current width of the treeview control.
TreeView_GetItemRect(item, node, prc, TRUE);
if(rc.left < area.left) area.left = rc.left;
if(rc.right > area.right) area.right = rc.right;
if(rc.top < area.top) area.top = rc.top;
if(rc.bottom > area.bottom) area.bottom = rc.bottom;
} while((node = TreeView_GetNextVisible(item, node)));
width = area.right - area.left;
height = area.bottom - area.top;
}

感谢 Hans Passant 让我走上正轨。

关于c++ - 如何获得避免滚动条的 TreeView 控件的最小尺寸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29027757/

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