CMFCShellTreeCtrl Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CMFCShellTreeCtrl Class.

The CMFCShellTreeCtrl class extends CTreeCtrl Class functionality by displaying a hierarchy of Shell items.

class CMFCShellTreeCtrl : public CTreeCtrl  

Public Methods

NameDescription
CMFCShellTreeCtrl::EnableShellContextMenuEnables or disables the shortcut menu.
CMFCShellTreeCtrl::GetFlagsReturns a combination of flags that are passed to IShellFolder::EnumObjects.
CMFCShellTreeCtrl::GetItemPathRetrieves the path to an item.
CMFCShellTreeCtrl::GetRelatedListReturns a pointer to the CMFCShellListCtrl Class object that is used together with this CMFCShellTreeCtrl object to create an Explorer-like window.
CMFCShellTreeCtrl::OnChildNotifyThis member function is called by this window's parent window when it receives a notification message that applies to this window. (Overrides CWnd::OnChildNotify.)
CMFCShellTreeCtrl::OnGetItemIcon
CMFCShellTreeCtrl::OnGetItemText
CMFCShellTreeCtrl::RefreshRefreshes and repaints the current CMFCShellTreeCtrl object.
CMFCShellTreeCtrl::SelectPathSelects the appropriate tree control item based on a supplied PIDL or string path.
CMFCShellTreeCtrl::SetFlagsSets flags to filter the tree context (similar to the flags used by IShellFolder::EnumObjects).
CMFCShellTreeCtrl::SetRelatedListSets a relation between the current CMFCShellTreeCtrl object and a CMFCShellListCtrl object.

This class extends the CTreeCtrl class by enabling your program to include Windows Shell items in the tree. This class can be associated with a CMFCShellListCtrl object to create a complete Explorer window. Then, selecting an item in the tree will display a list of Windows Shell items in the associated list.

CObject

CCmdTarget

CWnd

CTreeCtrl

CMFCShellTreeCtrl

Header: afxshelltreeCtrl.h

The following example demonstrates how to create an object of the CMFCShellTreeCtrl class. This code snippet is part of the Explorer sample.

	CMFCShellTreeCtrl	m_wndShellTree;

	// const int idTree = 1
	CRect rectDummy (0, 0, 0, 0);
	const DWORD dwViewStyle =	WS_CHILD | WS_VISIBLE | TVS_HASLINES | 
								TVS_LINESATROOT | TVS_HASBUTTONS;

	// The this pointer points to CFolderBar class which extends the CDockablePane class
	m_wndShellTree.Create (dwViewStyle, rectDummy, this, idTree);

Enables the shortcut menu.

void EnableShellContextMenu(BOOL bEnable = TRUE);

Parameters

[in] bEnable
A Boolean that specifies whether to enable the shortcut menu.

Returns the flags set for the CMFCShellTreeCtrl Class object.

DWORD GetFlags() const;  

Return Value

A DWORD value that specifies the combination of flags currently set.

Remarks

The flags set in the CMFCShellTreeCtrl are sent to the method IShellFolder::EnumObjects whenever the object is refreshed. You can change the flags with the CMFCShellTreeCtrl::SetFlags method.

Retrieves the path of an item in the CMFCShellTreeCtrl Class object.

BOOL GetItemPath(
    CString& strPath,  
    HTREEITEM htreeItem = NULL) const;  

Parameters

[out] strPath
A reference to a string parameter. The method writes the path of the item to this parameter.

[in] htreeItem
The method retrieves the path for this tree control item.

Return Value

Nonzero if successful; 0 otherwise.

Remarks

If this method fails, strPath contains the empty string.

If you do not specify hTreeItem, this method tries to obtain the string for the currently selected item. If no item is selected and hTreeItem is NULL, this method fails.

Returns a pointer to the CMFCShellListCtrl Class object that is associated with this CMFCShellTreeCtrl object.

CMFCShellListCtrl* GetRelatedList() const;  

Return Value

A pointer to the CMFCShellListCtrl object that is associated with this tree control object.

Remarks

By using a CMFCShellListCtrl object together with a CMFCShellTreeCtrl object, you can create an Explorer-like window. Use the method CMFCShellTreeCtrl::SetRelatedList to associate the two classes. After they are associated, the framework automatically updates the CMFCShellListCtrl if the selection in the CMFCShellTreeCtrl changes.

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

virtual BOOL OnChildNotify(
    UINT message,  
    WPARAM wParam,  
    LPARAM lParam,  
    LRESULT* pLResult);

Parameters

[in] message
[in] wParam
[in] lParam
[in] pLResult

Return Value

Remarks

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

virtual int OnGetItemIcon(
    LPAFX_SHELLITEMINFO pItem,  
    BOOL bSelected);

Parameters

[in] pItem
[in] bSelected

Return Value

Remarks

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

virtual CString OnGetItemText(LPAFX_SHELLITEMINFO pItem);

Parameters

[in] pItem

Return Value

Remarks

Refreshes and repaints the CMFCShellTreeCtrl.

void Refresh();

Remarks

Call this method to refresh the hierarchy of the items displayed in the CMFCShellTreeCtrl.

Selects an item in the CMFCShellTreeCtrl Class based on the supplied path.

BOOL SelectPath(LPCTSTR lpszPath);
BOOL SelectPath(LPCITEMIDLIST lpidl);
```  
  
### Parameters  
 [in] `lpszPath`  
 A string that specifies the path of an item.  
  
 [in] `lpidl`  
 A PIDL that specifies the item  
  
### Return Value  
 `S_OK` if successful; `E_FAIL` otherwise.  
  
##  <a name="cmfcshelltreectrl__setflags"></a>  CMFCShellTreeCtrl::SetFlags  
 Sets flags to filter the tree context.  
  

void SetFlags( DWORD dwFlags,
BOOL bRefresh = TRUE);

  
### Parameters  
 [in] `dwFlags`  
 The flags to set.  
  
 [in] `bRefresh`  
 A Boolean that specifies whether the [CMFCShellTreeCtrl Class](../Topic/CMFCShellTreeCtrl%20Class.md) should be refreshed immediately.  
  
### Remarks  
 The `CMFCShellTreeCtrl` passes all set flags to [IShellFolder::EnumObjects](http://msdn.microsoft.com/library/windows/desktop/bb775066). For more information about the values of different flags, see [IShellFolder::EnumObjects](http://msdn.microsoft.com/library/windows/desktop/bb775066).  
  
##  <a name="cmfcshelltreectrl__setrelatedlist"></a>  CMFCShellTreeCtrl::SetRelatedList  
 Associates a [CMFCShellListCtrl](../Topic/CMFCShellListCtrl%20Class.md) object with a [CMFCShellTreeCtrl](../Topic/CMFCShellTreeCtrl%20Class.md) object.  
  

void SetRelatedList(CMFCShellListCtrl* pShellList);

  
### Parameters  
 [in] `pShellList`  
 A pointer to a `CMFCShellListCtrl` object.  
  
### Remarks  
 This method associates a `CMFCShellListCtrl` with a `CMFCShellTreeCtrl`. These objects may be displayed as an Explorer-like window: if the user selects an object in the `CMFCShellTreeCtrl`, the associated items in the `CMFCShellListCtrl` will be automatically updated.  
  
 Use the method [CMFCShellTreeCtrl::GetRelatedList](#cmfcshelltreectrl__getrelatedlist) to retrieve the `CMFCShellListCtrl` associated with a `CMFCShellTreeCtrl`.  
  
## See Also  
 [Hierarchy Chart](../Topic/Hierarchy%20Chart.md)   
 [Classes](../Topic/MFC%20Classes.md)   
 [CTreeCtrl Class](../Topic/CTreeCtrl%20Class.md)   
 [CMFCShellListCtrl Class](../Topic/CMFCShellListCtrl%20Class.md)







Show: