One of the many GUI classes I have developed and published on my web site is ShellCtrls2. This is a enhanced version of the MFC classes of CMFCShellTreeCtrl and CMFCShellListCtrl provided with Visual C++. What I was unaware of at the time of implementing these classes is that Windows provides a built-in equivalent to CMFCShellTreeCtrl through a COM interface called INameSpaceTreeControl2 / INameSpaceTreeControl. Because this COM interface is a bit tricky to integrate with the MFC framework, I have developed CNameSpaceTreeCtrl which makes this job a bit easier. This code hides all the details of having to implement COM callback interfaces, grapple with implementing COM reference counting and having to call INameSpaceTreeCtrl::TreeUnadvise at specific times. The code also uses virtual functions which are easier to deal with instead of COM event interfaces. It also handles the low level details of the INameSpaceTreeControlEvents, INameSpaceTreeControlCustomDraw, INameSpaceTreeControlDropHandler and IShellItemFilter interfaces. The control also supports a good subset of the functionality of the ShellCtrls2 tree control class including file and folder filtering, access to the low level tree control class, Custom colors for compressed and encrypted items, Item selection and expansion, shell context menus, Drag and Drop and Refresh functionality.
The classes provided are:
CNameSpaceTreeControlEvents which provides a COM interface class to
encapsulate the IServiceProvider, INameSpaceTreeControlEvents,
INameSpaceTreeControlCustomDraw and INameSpaceTreeControlDropHandler interfaces.
CNameSpaceTreeControlFilter which provides a COM interface class to
encapsulate the IShellItemFilter interface suitable for use in the
INameSpaceTreeCtrl::AppendRoot API call.
CNameSpaceTreeCtrl l This is the main class which provides a wrapper for
the INameSpaceTreeControl / INameSpaceTreeControl2 interfaces.
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 2022 solution file to build a demo application to demonstrate all the classes.
v1.0 (28 March 2025)