void CDirectoryTreeCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
	UINT uFlags;
	HTREEITEM hItem = HitTest(point, &uFlags);
	HTREEITEM tItem = GetFirstVisibleItem();

	if((hItem) && (uFlags & TVHT_ONITEMSTATEICON))
	{
		CheckChanged(hItem, !GetCheck(hItem));

		if(nFlags & MK_CONTROL)
		{
			Expand(hItem, TVE_TOGGLE);
			HTREEITEM hChild;
			hChild = GetChildItem(hItem);
			while (hChild != NULL)
			{
				MarkChilds(hChild,!GetCheck(hItem));
				hChild = GetNextSiblingItem(hChild);
			}
			Expand(hItem, TVE_TOGGLE);
		}
	}
	SelectSetFirstVisible(tItem);
	CTreeCtrl::OnLButtonDown(nFlags, point);
}
Exemple #2
0
// Eine bestimmte Objekteigenschaft vorselektieren
bool CSelectObjectPropTree::SelectObjProp (LPCSTR pcObjProp)
{
HTREEITEM hItem = FindString (pcObjProp);

	if (NULL == hItem)
		return false;

	SelectSetFirstVisible (hItem);
	SelectItem (hItem);
	return true;
}
void CDirectoryTreeCtrl::OnTvnKeydown(NMHDR *pNMHDR, LRESULT *pResult)
{ 
	LPNMTVKEYDOWN pTVKeyDown = reinterpret_cast<LPNMTVKEYDOWN>(pNMHDR);

	switch(pTVKeyDown->wVKey)
	{
		case VK_SPACE:
		case VK_RETURN:
		{
			HTREEITEM hItem = GetSelectedItem();

			if(hItem)
			{		
				HTREEITEM tItem = GetFirstVisibleItem();

				CheckChanged(hItem, !GetCheck(hItem));
								
				if(m_bCtrlPressed)
				{
					Expand(hItem, TVE_TOGGLE);
					HTREEITEM hChild;
					hChild = GetChildItem(hItem);

					while(hChild != NULL)
					{ 
						MarkChilds(hChild,!GetCheck(hItem));
						hChild = GetNextSiblingItem( hChild );
					}

					SetCheck(hItem, !GetCheck(hItem));
					Expand(hItem, TVE_TOGGLE);
				}
		 
				SelectSetFirstVisible(tItem);
			}

			break;
		}

		default:
			break;
	}

	*pResult = 0;
}
BOOL CMyTreeView::GetRootItems()
{
    DeleteAllItems();
    Cpidl cpidlDesk;
    cpidlDesk.SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP);

    if (cpidlDesk.GetPidl()) {
        TV_ITEM           tvItem = {0};
        TV_INSERTSTRUCT   tvInsert = {0};
        HTREEITEM         hParentItem;
        //fill in the TVITEM structure for this item
        tvItem.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN;
        //Store a pointer to the TreeItemData in the lParam and m_pItems
        TreeItemData* pItem = new TreeItemData(cpidlDesk);
        tvItem.lParam = (LPARAM)pItem;
        m_pItems.push_back(pItem);
        //text and images are done on a callback basis
        tvItem.pszText = LPSTR_TEXTCALLBACK;
        tvItem.iImage = tvItem.iSelectedImage = I_IMAGECALLBACK;
        //assume the desktop has children
        tvItem.cChildren = TRUE;
        //fill in the TV_INSERTSTRUCT structure for this item
        tvInsert.item = tvItem;
        tvInsert.hInsertAfter = TVI_LAST;
        tvInsert.hParent = TVI_ROOT;
        SetFocus();
        //add the item
        hParentItem = InsertItem(tvInsert);
        //go ahead and expand this item
        Expand(hParentItem, TVE_EXPAND);
        //Select the next item
        HTREEITEM hNext = GetNextItem(hParentItem, TVGN_CHILD);
        //Expand this item
        Expand(hNext, TVE_EXPAND);
        //Select this item
        SelectItem(hNext);
        //Scroll this item into view
        SelectSetFirstVisible(hNext);
        return TRUE;
    }

    return FALSE;
}
void CDirectoryTreeCtrl::ShareSubDirTree(HTREEITEM hItem, BOOL bRecurse)
{
	CWaitCursor curWait;
	SetRedraw(FALSE);

	HTREEITEM hItemVisibleItem = GetFirstVisibleItem();
	CheckChanged(hItem, !GetCheck(hItem));
	if (bRecurse)
	{
		Expand(hItem, TVE_TOGGLE);
		HTREEITEM hChild = GetChildItem(hItem);
		while (hChild != NULL)
		{
			MarkChilds(hChild, !GetCheck(hItem));
			hChild = GetNextSiblingItem(hChild);
		}
		Expand(hItem, TVE_TOGGLE);
	}
	if (hItemVisibleItem)
		SelectSetFirstVisible(hItemVisibleItem);

	SetRedraw(TRUE);
	Invalidate();
}