|
|
Namespace Tree control
While you don't actually need the WTL library to use the new Vista control, I
decided that it would be easier to deal with if it acted like the regular
To create the control, add a member variable to the window or dialog:
And then in during window creation, initialize it:
The Create() method can optionally take a few flags to configure how
the control should appear, not unlike the regular TVS_XXX style flags.
The above sample code adds the Desktop to the tree as a root item. You can add several roots to the tree through some of the helper methods the wrapper exposes. You can also specify if each root should just display its folders, or even display non-folder items, such as files.
When your window is destroyed, you must manually call the
Once the tree is initialized with items, you will start receiving window notify
messages in the form of
However unlike the regular tree and list controls, the Namespace Tree control
refers to its items via a IShellItem COM object. The Shell item object
is a wrapper for the old PIDL structure way of accessing the available items. My
old sample needed these PIDL structures (or
LPCITEMIDLIST pointers) to refer to the shell hierarchy,
but it always seemed a little odd for non-savvy Shell programmers that when
you needed to query a file for some attributes you would have to talk to it
through its folder.
The Shell item object offers a neat COM wrapper to the same underlying structures.
To get from a filename to a Shell item and back, you can use the following access functions in Windows Vista.
The strFilename variable now contains a pointer to a wide-string
filename. It is automatically freed using the OLE allocator.
It may seem a little convoluted at first, but keeping things IShellItem
in your code for as long as possible can be a great help rather than instantly
converting them to paths. Remember that not all Shell items are file-system objects,
some are virtual objects and they may not translate to an actual physical
file-system path.
Interface
Source Code DependenciesWindows VistaMicrosoft Visual Studio.NET 2008 Microsoft WTL 7.5 Library Microsoft ATL Library See AlsoProject where control is usedMy Shell controls for pre-Vista Download Files
Written by Bjarke Viksoe. Article submitted 1/3/2009. To the top
|
||||||||||||||||||||||||||||||||||||||||||||||||