
Introduction
These templates allow CTreeCtrl derived classes programmers to add three basic functionalities to their classes:
- Iteration of all the items in the control
- Persistence of the status of the control (when you reload it, it tries to return to its previous state)
- Expand / Collapse all the items in the tree
Sample Code 1: Deep Iteration
mc_tcTree.Initialize(true);
HTREEITEM hItem= mc_tcTree.GetNext();
while (hItem != NULL)
{
TRACE(mc_tcTree.GetItemText(hItem) + "\n");
hItem= mc_tcTree.GetNext();
}
Sample Code 2: Width Iteration
mc_tcTree.Initialize(false);
HTREEITEM hItem= mc_tcTree.GetNext();
while (hItem != NULL)
{
TRACE(mc_tcTree.GetItemText(hItem) + "\n");
hItem= mc_tcTree.GetNext();
}
Sample Code 3: Expanding All Items
mc_tcTree.SetRedraw(FALSE);
mc_tcTree.ExpandItem();
mc_tcTree.SetRedraw(TRUE);
Sample Code 4: Collapsing All Items
mc_tcTree.SetRedraw(FALSE);
mc_tcTree.ExpandItem(TVI_ROOT, TVE_COLLAPSE);
mc_tcTree.SetRedraw(TRUE);
Sample Code 5: Status Preservation
mc_tcTree.SaveStatus();
PopulateTree();
mc_tcTree.RestoreStatus();
That's all folks!