void CSettingsDialog::ExpandTree()
{
	HTREEITEM hti = m_TreeCtrl.GetRootItem();
	while (hti)
	{
		ExpandBranch(hti);
		hti = m_TreeCtrl.GetNextSiblingItem(hti);
	}
}
void CSettingsDialog::ExpandBranch(HTREEITEM hti)
{
	if( m_TreeCtrl.ItemHasChildren( hti ) )
	{
		m_TreeCtrl.Expand( hti, TVE_EXPAND );
		hti = m_TreeCtrl.GetChildItem( hti );
		do
		{
			ExpandBranch( hti );
		} while( (hti = m_TreeCtrl.GetNextSiblingItem( hti )) != NULL );
	}
	m_TreeCtrl.EnsureVisible( m_TreeCtrl.GetSelectedItem() );
}
BOOL COXNetBrowseTree::BuildTreeContents()
{

	SetRedraw(FALSE);

	// If the tree till contains nodes, remove them all
	DeleteAllItems();

	// Cleanup data members
	Cleanup();

	// Create the root node
	if (0 < m_nMaxNumLevels)
		ExpandNode(NULL);

	// Expand all top level items
	HTREEITEM hTopItem = NULL;
	hTopItem = GetRootItem();
	while (hTopItem != NULL)
	{
		ExpandBranch(hTopItem, m_nInitialExpandLevel);
		hTopItem = GetNextSiblingItem(hTopItem);
	}

	// If at least one top level item is expandable, connect lines to 
	// the root of the control otherwise do not
	BOOL bLinesAtRoot = FALSE;
	hTopItem = GetRootItem();
	while(!bLinesAtRoot && (hTopItem  != NULL))
	{
		bLinesAtRoot = ItemHasChildren(hTopItem);
		hTopItem = GetNextSiblingItem(hTopItem);
	}
	if (bLinesAtRoot)
		ModifyStyle(0, TVS_LINESATROOT /* add */);
	else
		ModifyStyle(TVS_LINESATROOT /* remove */, 0);

	SetRedraw(TRUE);

	return TRUE;
}
void COXNetBrowseTree::ExpandBranch(HTREEITEM hParentItem, int nLevels)
{
	if (nLevels <= 0)
		return;

	ASSERT(hParentItem != NULL);

	// First expand the parent itself
	if (!Expand(hParentItem, TVE_EXPAND))
		// ... Expand failed (the network resource probably produced an error)
		return;

	// Then expand all its children
	HTREEITEM hChildItem = GetChildItem(hParentItem);
	while (hChildItem != NULL)
	{
		ExpandBranch(hChildItem, nLevels - 1);
		hChildItem = GetNextSiblingItem(hChildItem);
	}
}