viksoe.dk

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*/)
{
  ...
  m_tree.SubclassWindow(GetDlgItem(IDC_TREE1));
  m_list.SubclassWindow(GetDlgItem(IDC_LIST1));
  m_combo.SubclassWindow(GetDlgItem(IDC_COMBOBOXEX1));
  ...
}
Then add the following reflection macro to your main message map:
BEGIN_MSG_MAP(CMainDlg)
  ...
  REFLECT_NOTIFICATIONS()
END_MSG_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.

m_tree.Populate();
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*/)
{
  LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)pnmh;
  CPidl pidl;
  m_tree.GetItemPidl(pnmtv->itemNew.hItem, &pidl);
  m_list.Populate(pidl);
  m_combo.Populate(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
{
public:
   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);
ATLASSERT(SUCCEEDED(hRes));
_Module.m_Allocator.Init();
int nRet = Run(lpstrCmdLine, nCmdShow);
_Module.m_Allocator.Term();
_Module.Term();

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