如题

解决方案 »

  1.   

    CTreeCtrl::Expand Call this function to expand or collapse the list of child items, if any, associated with the given parent item.
     
    BOOL Expand(
       HTREEITEM hItem,
       UINT nCode 
    );Parameters
    hItem
    Handle of the tree item being expanded.nCode
    A flag indicating the type of action to be taken. This flag can have one of the following values:TVE_COLLAPSE   Collapses the list.
    TVE_COLLAPSERESET   Collapses the list and removes the child items. The TVIS_EXPANDEDONCE state flag is reset. This flag must be used with the TVE_COLLAPSE flag.
    TVE_EXPAND   Expands the list.
    TVE_TOGGLE   Collapses the list if it is currently expanded or expands it if it is currently collapsed.Return Value
    Nonzero if successful; otherwise 0.
      

  2.   

    遍历树控件,对每个有子接点的item都m_Tree.Expand(hParent,TVE_EXPAND);HTREEITEM hItem=m_Tree.GetNextItem(TVI_ROOT,TVGN_ROOT);
    while(hItem!=NULL)
    {
    UpdateTreeChildItem(hItem);
    hItem=m_Tree.GetNextSiblingItem(hItem);
    }
    void CHoop::UpdateTreeChildItem(const HTREEITEM Item)
    {
    if(Item == NULL)
    return;
    if(m_Tree.ItemHasChildren(Item))
    {
                      m_Tree.Expand(Item,TVE_EXPAND);
    HTREEITEM hChild = m_Tree.GetChildItem(Item);
    UpdateTreeChildItem(hChild);
    UpdateTreeChildItem(m_Tree.GetNextSiblingItem(hChild));
    }
    }