简体   繁体   English

MFC如何让ctreectrl虚拟?

[英]MFC How to make ctreectrl virtual?

My application is displaying a Hugh amount of files system entries held in memory using a ctreectrl , adding all the items takes ~20seconds even when using SetRedraw(False) , so how to make a completely virtual(breadth,depth) ctreectrl & how to populate it ? 我的应用程序使用ctreectrl显示在内存中保存的大量文件系统条目,即使使用SetRedraw(False) ,所有项目也需要~20 SetRedraw(False) ,因此如何制作完全虚拟(广度,深度)的ctreectrl以及如何填充它?

Edit#1 I want to display the displayed portion items expanded from the beginning , but I don't want to store them in the tree, for example 编辑#1我想显示从头开始展开的显示部分项目,但我不想将它们存储在树中,例如

Root-->
    Child1-->
        SubChile1
    Child2
    Child3

you must not add all items at once. 您不能一次添加所有项目。 you must add only top level items with cChildren = I_CHILDRENCALLBACK and handle WM_NOTIFY 你必须只用cChildren = I_CHILDRENCALLBACK添加顶级项目并处理WM_NOTIFY

  • with code == TVN_GETDISPINFO if mask & TVIF_CHILDREN set cChildren (TRUE or FALSE) 使用code == TVN_GETDISPINFO如果mask & TVIF_CHILDREN设置cChildren (TRUE或FALSE)
  • with code == TVN_ITEMEXPANDING , action == TVE_EXPAND - expand node - add only direct child items (one level) again with cChildren = I_CHILDRENCALLBACK 使用code == TVN_ITEMEXPANDINGaction == TVE_EXPAND - 展开节点 - 使用cChildren = I_CHILDRENCALLBACK再次添加直接子项(一个级别)

and possible 并且可能

  • with code == TVN_ITEMEXPANDED , action == TVE_COLLAPSE - collapse node - remove all childs 使用code == TVN_ITEMEXPANDEDaction == TVE_COLLAPSE - 折叠节点 - 删除所有子节点

sense of cChildren = I_CHILDRENCALLBACK - if you add folder to list, you not need at once initialize it (open handle, enum childs) - only when you first time got I_CHILDRENCALLBACK (this when your item become visible, but if containing folder large enough(like system32 ) - it have too many items, but visible only several top at begin, new begin visible when user scroll down)- open folder, determinate are it have subitems (and based on this set cChildren ) but not full enumerate it (do this only on <TVN_ITEMEXPANDING, TVE_EXPAND> 感觉cChildren = I_CHILDRENCALLBACK - 如果你将文件夹添加到列表中,你不需要立即初始化它(打开句柄,枚举孩子) - 只有当你第一次得到I_CHILDRENCALLBACK (这当你的项目变得可见时,但是如果包含足够大的文件夹(像system32 ) - 它有太多的项目,但在开始时只能看到几个顶部,当用户向下滚动时新的开始可见) - 打开文件夹,确定它是否有子项(并且基于此设置cChildren )但不完全枚举它(做这仅限于<TVN_ITEMEXPANDING, TVE_EXPAND>

I have no advice to make it virtual. 我没有建议让它虚拟化。 I use for large tree structures the possibility of collecting a child branch only when it is need. 我用于大型树结构,只有在需要时才可以收集子分支。 I trap TVN_ITEMEXPANDING 我陷阱TVN_ITEMEXPANDING

So how to do it: First read the first level (root), than keep all root node collapsed and read all child nodes of the root (just 1 level deep) and populate them. 那么怎么做:首先读取第一级(root),然后保持所有根节点折叠并读取根的所有子节点(只有1级深度)并填充它们。

When a node expands, you already have the nodes, now read the next level below the childs of the expanding node. 当节点扩展时,您已经拥有节点,现在读取扩展节点的子节点下面的下一级别。

So you see only the expanded nodes plus one invisible level. 所以你只看到扩展节点加上一个不可见的级别。

I do this in this way to show all nodes that are expandable with the + sign. 我这样做是为了显示所有可用+符号扩展的节点。 All nodes without children nodes are shown without it as leafs. 没有子节点的所有节点都显示为没有叶子。

The second way is not to fill the string data and let the tree load it via callback. 第二种方法是不填充字符串数据,让树通过回调加载它。 But the impact is small. 但影响很小。 The real problem with the speed are the number of nodes. 速度的真正问题是节点数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM