Copy a branch

To copy a branch, we use recursion and the CopyItem()
function to accomplish our task.

// CopyBranch           – Copies all items in a branch to a new location
// Returns              – The new branch node
// htiBranch            – The node that starts the branch
// htiNewParent – Handle of the parent for new branch
// htiAfter             – Item after which the new branch should be created
HTREEITEM CTreeCtrlX::CopyBranch( HTREEITEM htiBranch, HTREEITEM htiNewParent, 
                                                HTREEITEM htiAfter /*= TVI_LAST*/ )
        HTREEITEM hChild;

        HTREEITEM hNewItem = CopyItem( htiBranch, htiNewParent, htiAfter );
        hChild = GetChildItem(htiBranch);
        while( hChild != NULL)
                // recursively transfer all the items
                CopyBranch(hChild, hNewItem);  
                hChild = GetNextSiblingItem( hChild );
        return hNewItem;

More by Author

Must Read