Shell Aware Controls

Shell Aware Controls

This article was submitted .

The Shell Controls are subclassed tree, listview and combobox controls that display the file hierarchy information obtained from the shell.
Also included are some conversion functions between filenames and file system PIDLs, and a CExplorerMenu class for displaying the context menu of any shell object. The controls use some of the helper classes from my ATL Shell library (see link below for download).

To use them, place a TreeView, ListView and a ComboBoxEx control on your dialog.
Add these member variables to your dialog implementation file...

CShellTreeCtrl m_tree;
CShellListCtrl m_list;
CShellComboCtrl m_combo;
In the OnInitDialog() event handler, add the following lines:
LRESULT OnInitDialog(UINT /*uMsg*/, 
                     WPARAM /*wParam*/, 
                     LPARAM /*lParam*/, 
                     BOOL& /*bHandled*/)
Then add the following reflection macro to your main message map:

Use the SetShellStyle() method to filter the items shown in the controls. The SCT_EX_FILESYSTEMONLY style, for instance, removes Shell Extensions (such as the Recycle Bin) from the view.
Add the following line to automatically initialise the tree with the desktop folder tree.

As an example, you can synchronize the listview and combobox with the tree by handling the treeview's TVN_SELCHANGED notification.
LRESULT OnSelChanged(int /*idCtrl*/, 
                     LPNMHDR pnmh, 
                     BOOL& /*bHandled*/)
  CPidl pidl;
  m_tree.GetItemPidl(pnmtv->itemNew.hItem, &pidl);
  return 0;

To use my ATL Shell Classes in WTL, you need to initialise them properly.
Change the stdafx.h CAppModule definition:

#include "atlshellextbase.h"
class CMyAppModule : public CAppModule
   CShellMalloc m_Allocator;
extern CMyAppModule _Module;
#include "atlshellext.h"
Then modify the _tWinMain() function to initialise and terminate the new m_Allocator member:
hRes = _Module.Init(NULL, hInstance);
int nRet = Run(lpstrCmdLine, nCmdShow);

To use the ComboBoxEx derived CShellComboCtrl control you must initialise the Common Control Classes with the ICC_USEREX_CLASSES flag using the ::InitCommonControlsEx() call.

Source Code Dependencies

Microsoft Visual C++ 6.0
Microsoft WTL 3.0 Library

See Also

My ATL Shell Extension classes

Download Files

DownloadSource Code and sample (55 Kb)

To the top