简体   繁体   中英

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 ?

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

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

  • with code == TVN_GETDISPINFO if mask & TVIF_CHILDREN set cChildren (TRUE or FALSE)
  • with code == TVN_ITEMEXPANDING , action == TVE_EXPAND - expand node - add only direct child items (one level) again with cChildren = I_CHILDRENCALLBACK

and possible

  • with code == TVN_ITEMEXPANDED , action == TVE_COLLAPSE - collapse node - remove all childs

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>

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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