You can use the source code of the CExtShellDialogFile
class as the sample. This dialog has 4 shell controls:
CExtNCSB < CExtShellListCtrl > m_wndShellList;
CExtNCSB < CExtShellTreeCtrl > m_wndShellTree;
CExtNCSB < CExtShellComboBox > m_comboLookIn;
CExtShellExtensionsComboBox m_comboFileTypes;
It initializes these controls in the
CExtShellDialogFile::OnInitDialog()
virtual method and handles notification from the shell controls for synchronizing them with each other:
ON_REGISTERED_MESSAGE( CExtShellListCtrl::g_nMsgShellLocationChanged, OnShellListLocationChanged )
ON_REGISTERED_MESSAGE( CExtShellComboBox::g_nMsgShellLocationChanged, OnShellComboLocationChanged )
ON_REGISTERED_MESSAGE( CExtTreeCtrl::g_nMsgTreeItemDelayedFocus, OnShellTreeDelayedItemFocus )
ON_REGISTERED_MESSAGE( CExtShellBase::g_nMsgShellItemExecute, OnShellItemExecute )
Now we will use code lines from the method to show you how to initialize shell tree and shell list controls. The shell tree control initialization is mostly performed by one line of code:
m_wndShellTree.RefreshShellRoot();
Then you can focus some tree item:
m_wndShellTree.FocusItem( m_wndShellTree.GetChildItem( TVI_ROOT ), true, false, true );
Then you can display content of the corresponding shell folder in the shell list control:
HTREEITEM htiSelect = m_wndShellTree.GetFocusedItem();
if( htiSelect != NULL )
{
CExtTreeCtrl::TREEITEMINFO_t & _TII = m_wndShellTree.TreeItemInfoGet( htiSelect );
CExtShellItemData * pData = (CExtShellItemData*)_TII.m_lParam;
ASSERT( pData != NULL );
LPITEMIDLIST pidlSelect = (LPITEMIDLIST)pData->m_pidlAbsolute.GetPtr();
ASSERT( pidlSelect != NULL );
m_wndShellList.FocusPIDL( pidlSelect );
}
The shell combo box above shell list and tree controls is also initialized with one line of code:
m_comboLookIn.DelayFocusPIDL( pidlSelect );
Then you should take a look at the
CExtShellDialogFile::OnShellTreeDelayedItemFocus()
,
CExtShellDialogFile::OnShellListLocationChanged()
,
CExtShellDialogFile::OnShellComboLocationChanged()
and
CExtShellDialogFile::OnShellItemExecute()
handler methods which perform synchronization between shell controls. The first three handler methods are invoked when the focused shell item is changed in the shell combo/tree/list controls. The
CExtShellDialogFile::OnShellItemExecute()
method is invoked when user double clicks on some shell item in the shell control. If this control is shell list, then the file dialog should assume the
IDOK
button is clicked.