BOOL CSelectionsDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon
    
    m_vDir1 = m_Dir1.GetControlUnknown();
    m_vDir2 = m_Dir2.GetControlUnknown();

    // This sample uses 2 SftDirectory controls
    // SftDirectory1 allows single selection only
    m_vDir1->MultiSelect = selectSftDirectorySingle;
    // SftDirectory2 allows multiple selection
    m_vDir2->MultiSelect = selectSftDirectoryMultiple;

    return TRUE;
}

// This is a button event handler
void CSelectionsDlg::OnButton1() 
{
    // Select one file/folder (in a single selection control)
    m_vDir1->FolderList[1]->Selected = VARIANT_TRUE;
    // Select a few files/folders (in a multiple selection control)
    m_vDir2->FolderList[1]->Selected = VARIANT_TRUE;
    m_vDir2->FolderList[3]->Selected = VARIANT_TRUE;
    m_vDir2->FolderList[5]->Selected = VARIANT_TRUE;
}

// This is another button event handler
void CSelectionsDlg::OnButton2() 
{
    // Show the selected file/folder (in a single selection control)
    ISftDirectoryFolderPtr pFolder;
    pFolder = m_vDir1->Selection[0];
    if (pFolder != NULL) {
        CString str;
        CString strName((LPCWSTR)pFolder->Name);
        str.Format(_T("\"%s\" is selected (in the single selection control)."), strName);
        AfxMessageBox(str);
    }
    // Show the selected files/folders (in a multiple selection control)
    int i;
    for (i = 0 ; i < m_vDir2->SelectionCount ; ++ i) {
        pFolder = m_vDir2->Selection[i];
        CString strName((LPCWSTR)pFolder->Name);
        CString str;
        str.Format(_T("\"%s\" is selected (in the multiple selection control)."), strName);
        AfxMessageBox(str);
    }
}