[VB6] ucShellTree - Full-featured Shell Tree UserControl
ucShellTree v2.7
Released 25 January 2022
About
Designed for navigating the Windows Shell, like my recent Shell Browser Control, ucShellBrowse. This UserControl shows an Explorer-style TreeView of the entire shell, descended from the Desktop like normal. It's very similar to the INamespaceTreeControl in functionality and features, but a manual implementation allows a few extras that aren't available, like automatically handled tri-state checkboxes and open-to-path, and the ability to implement further customizations.
Key Features
Displays complete Explorer-type tree with either Desktop, Computer, or a custom path as the root folder.
Tri-state checkboxes show partial selections when check mode is enabled, 4th state with red x is available as an option.
Supports drag/drop with modern drag images and drag-over-highlighting (including expanding on hover), based on my cDropTarget project. Can drop on all valid drop targets: folders, zip files, programs, shortcuts to them, etc.
Right-click shows the standard Explorer context menu for the clicked item
Automatically monitors for changes (item created, deleted, renamed) and updates the tree accordingly.
Option to show files as well
Can automatically expand to a given path.
InfoTips with several lines of details depending on file type are shown as ToolTips
Filter option can limit the type of files displayed (or even folders)
Can rename in place using LabelEdit
Can (optionally) treat .zip/.cab files as a folder
Optional additional root entry for 'Favorites' that shows the Links folder.
Browses the Network folder too and returns paths as \\Share\etcetc
Complete Unicode support
Requirements
-Windows Vista or newer
-oleexp 4.42 or higher (not needed once compiled into OCX)
Strongly recommended: Common Controls 6.0 Manifest (see here). The Demo projects have a manifest added for when they're compiled, but the IDE and your own projects will need their own. The control works without it, but I haven't fully explored what other things might break without it. This paragraph previously mentioned checkbox issues--- there's no partial checkboxes or exclusion checkboxes but the project now gets the checkboxes from Windows rather than its own, so normal unthemed checks are fine.
DemoSB: In the DemoSB folder, there's a project that shows the use of ucShellTree with my ucShellBrowse control. This requires ucShellBrowse to be present in the same root as ucShellTree (e.g. C:\vb6\ucShellBrowse and C:\vb6\ucShellBrowse). You can also see this done in the DemoEx sample in the ucShellBrowse download.
Compiling to OCX
It's very simple to use the control as an OCX: Open ShellTree.vbp from the main folder, double-click ucShellTree.ctl in the project explorer (under UserControls), and in the properties for the control, change Public to True, you can then compile. Then proceed to move, register, and use as you would any other .ocx. UPDATE: A project with the OCX requires oleexp.tlb if you want to respond to any event with an IShellItem or IShellItemArray member. I'm sorry for providing inaccurate information about the need to include it in the past.
The demo projects use the control as a .ctl.
Works with ucShellBrowse
(Optional -- You can of course use this control by itself without the presence of ucShellBrowse)
This project is similar to my recent ucShellBrowse control, and indeed if you prefer a TreeView to the dropdown for navigation, this control works seamlessly with it-- since it can be put into FilesOnly mode. There's a demo project of this setup in the \DemoSB folder (ucShellBrowse DL'd separate, grab the latest version from the ucShellBrowse project thread -- which has its own version of the demo in DemoEx).
There's even an optional feature for seamless integration with the layout options. The ShellTreeInLayout option in ucShellBrowse adds a menu item to allow the user to toggle the ShellTree control (by raising the ShowShellTree event, notifying you to show or hide it) from the ShellBrowse control's layout menu:
Recent Updates
UPDATE - 25 Jan 2022
-Project updated to 2.7.
Code:
-Added ShowHiddenItems/ShowSuperHidden options
-Added EnableShellMenu option to control whether the right-click menu pops up.
-Added SetFocusOnTree method.
-Added public event for UserControl_EnterFocus and UserControl_ExitFocus (EnterFocus
and ExitFocus, respectively).
-(Bug fix) Keyboard focus never went to ucTreeView when on a form with ucShellBrowse.
UPDATE - 03 April 2021
Project updated to v2.6. Small update to address a bug in OCX builds, add Select/Click events with IShellItem references, remove the need to track a variable when combined with ucShellBrowse for directory changes (bChanging in the demos), and add a SelectNone sub to deselect.
Code:
'v2.6 (Released 03 Apr 2021)
'
'-Eliminated the need to use a variable to keep tracking of dir change operations when
' combining this control with a ucShellBrowse control; previously you'd handle a path
' change notification from the browser with
' If bChanging = False Then
' bChanging = True
' ucShellTree1.OpenToItem siItem, False
' bChanging = False
' End If
' Now you no long need the bChanging variable.
'
'-Added SelectNone sub, which will clear all selected items (supports multiselect).
'
'-Added ItemSelectByShellItem event. I wanted to just include an IShellItem member in
' ItemSelect, but the backwards compatibility concerns are too great. This event will
' also include all the information of ItemSelect if you want to fully switch over.
'-Did the same for ItemClick->ItemClickByShellItem
'
'-For MultiSelect, added the MultiSelectChange event, which includes an IShellItemArray
' of selected items as well as a name list and full path list
'
'-(Bug fix) Using On Error Resume Next to handle an uninitialized array in the Terminate
' event caused the control to freeze on compile or on run after changes if
' you were using it as an OCX.
UPDATE - 09 December 2020
Project updated to v2.5 R2 - Critical bug fix; when navigating in the Network folder via OpenToItem (usually from a ShellBrowse control), and potentially other non-standard locations, if the folder wasn't manually expanded, automatic expansion would error out and not expand.
Project updated to v2.5. Unbelievably, the control never had BackColor/ForeColor options. Those have been added. Also added a full RefreshTreeView function. Previously there was ResetTreeView, which loaded the initial state. But RefreshTreeView will now rebuild all the folders you had open before the Refresh. Also fixed a mobile device bug.
While you're at it, check out the update to ucShellBrowse on the same day as this--- it lets you integrate the two much more closely:
UPDATE - 20 September 2020
Project updated to v2.4 in order to eliminate all non-explicit types defined in the TLB. These would cause a show-stopping conflict if the control was used in a project that had any of these as a Public Type, or in a project with them defined in another TLB if it was a higher priority. Also, added AlwaysShowExtendedVerbs option; these are no longer shown by default in the Shell Context Menu, you need to hold Shift when bringing up the menu if this option is False.
I'm also now distributing ucShellBrowse and ucShellTree together as a compiled OCX, complete with SxS resources to create registration-free distributions.
A more recent version of this control is available for twinBASIC that is 64bit compatible and can still be compiled as an OCX for use in VB6 (or any other host): ShellControls GitHub
Last edited by fafalone; Apr 9th, 2024 at 01:42 PM.
Reason: Link to tB version