
One of the many GUI classes I have developed and published on my web site is
CFileTreeCtrl. This is a
implementation from first principles of a tree control similar to the left hand
side of Windows Explorer. Because it was implemented with custom code, it has diverged
from the tree control shown in Windows Explorer in recent versions of Windows.
In addition, some
features in CFileTreeCtrl such as network enumeration no longer work in recent versions
of Windows. In addition It would be nice to have a list control implementation
similar to the right hand side of Windows Explorer. As of Visual Studio 2008 Service
Pack 1, two classes became available which implemented this functionality using
MFC. They are called CMFCShellTreeCtrl and CMFCShellListCtrl. I've recently taken
a look at these two classes, but I wanted to bring forward all the functionality
of CFileTreeCtrl in an implementation which provides better integration with the
shell. I also took inspiration and ideas from the following codeproject articles:
https://www.codeproject.com/Articles/1073213/Extending-MFC-shell-controls-functionality
and https://www.codeproject.com/Articles/2271/ShellFolderTree.
The result of all this work is ShellCtrls2.
The classes provided are:
CPIDL which provides a RAII class wrapper for a LPITEMIDLIST aka PIDLs.
PIDLs are identifiers which the Windows shell uses to identify all objects which
make up the Shell namespace. This class is based on the PIDL class provided by Oz
Solomon with WndTabs extension for Visual C++
6.0 but reimplemented using modern C++ 11 idioms.
CShellItemInfo2 This class is what
is stored in the item data for each item in the tree control or list control
CShellTreeCtrl2 This class is an improved version of the built-in MFC class
CMFCShellTreeCtrl
CShellListCtrl2 This class is an improved version of
the built-in MFC class CMFCShellListCtrl
CShellCtrl2DropTarget
This class is used to support OLE Drag / Drop in CShellTreeCtrl2 and
CShellListCtrl2
CShellCtrlScopedRedraw This class is used in CShellTreeCtrl2 and
CShellListCtrl2 to provide a simple RAII wrapper for the SetRedraw(FALSE),
SetRedraw(TRUE) & RedrawWindow() calling sequence.
The demo application included in the download exercises all the functionality
of each of the classes. A screen capture of the sample app running is as follows:

The enclosed zip file contains source
code for the classes along with a VC 2019 solution file to build a demo
application to demonstrate all the classes.
Copyright
- You are allowed to include the source code in any product (commercial, shareware,
freeware or otherwise) when your product is released in binary form.
- You are allowed to modify the source code in any way you want except you
cannot modify the copyright details at the top of each module.
- If you want to distribute source code with your application, then you are
only allowed to distribute versions released by the author. This is to maintain
a single distribution point for the source code.
Updates
v1.07 (3 May 2025)
- Updated copyright details.
- Removed the unused function CShellTreeCtrl2::ExpandAll.
- Optimized and refactored the code in CShellTreeCtrl2::SelectPath.
- Defaulted CShellTreeCtrl2::m_bRefreshAfterShellCommand to false.
- Updated behavior of context menu to be more consistent with Windows
Explorer in CShellTreeCtrl2.
- Updated CShellTreeCtrl2 code to support the context menu in
addition to OLE right mouse Drag Drop support at the same time.
- Reworked CShellTreeCtrl2 code to use INamespaceWalk COM interface for
Shell enumeration.
v1.06 (14 December 2024)
- Updated CShellTreeCtrl2 class to use new CShellCtrlScopedRedraw class.
- Updated CShellListCtrl2 class to use new CShellCtrlScopedRedraw class.
- CShellTreeCtrl2::OnBeginDrag now does not do a Refresh after the
operation completes.
- CShellListCtrl2::OnBeginDrag now does not do a Refresh after the
operation completes.
- CShellTreeCtrl2::OnSelChanged now does not notify the associated list
control if the item selected does not have the SFGAO_FOLDER attribute set.
- Updated CShellTreeCtrl2 class to use std::filesystem::path class.
- Updated CShellListCtrl2 class to use std::filesystem::path class.
v1.05 (12 December 2024)
- Added Right mouse OLE Drag Drop support to CShellTreeCtrl2 class
- Added Right mouse OLE Drag Drop support to CShellListCtrl2 class
- Fixed an issue where a folder that contain no child items will show a
‘+’ preceding them, but when you clicked on the ‘+’, the ‘+’ did not get
removed.
- Updated CShellTreeCtrl2::OnBeginDrag to use SHDoDragDrop.
- Updated CShellListCtrl2::OnBeginDrag to use SHDoDragDrop.
- Removed logic to auto expand folders when dragging files into
CShellListCtrl2 to be consistent with modern Windows Explorer.
v1.04 (11 December 2024)
- Updated copyright details.
- Added missing SAL to CShellTreeCtrl2
- Added OLE Drag Drop support to CShellTreeCtrl2 class
- Added missing SAL to CShellListCtrl2 class
- Added OLE Drag Drop support to CShellListCtrl2
v1.03 (4 June 2023)
- Updated copyright details.
- Reworked CShellListCtrl2::OnGetItemText to use IShellItem2.
- Reworked CShellListCtrl2::OnCompareItems to use IShellItem2.
- Reworked the logic in CShellListCtrl2::OnCompareItems to behave more
similar to how Windows Explorer behaves.
v1.02 (23 April 2022)
- Updated copyright details
- Updated the code to use C++ uniform initialization for all variable
declarations.
v1.01 (17 December 2021)
- Updated copyright details
- Fixed more static code analysis warnings in the code.
v1.0 (25 July 2020)