Hide

SftDirectory 3.5 - ActiveX File/Folder Control

Display
Print

Filtering Sample (C++)

This sample illustrates filtering (limiting) the files/folders shown.

This is not an executable sample, so a complete project is not provided. These statements are intended to show the syntax used.

// FilteringDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Filtering.h"
#include "FilteringDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFilteringDlg dialog

CFilteringDlg::CFilteringDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CFilteringDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CFilteringDlg)
        // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFilteringDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CFilteringDlg)
    DDX_Control(pDX, IDC_SFTDIRECTORY1, m_Dir1);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFilteringDlg, CDialog)
    //{{AFX_MSG_MAP(CFilteringDlg)
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CFilteringDlg::OnPaint()
{
    if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialog::OnPaint();
    }
}

HCURSOR CFilteringDlg::OnQueryDragIcon()
{
    return (HCURSOR) m_hIcon;
}

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

    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon

    m_vDir1 = m_Dir1.GetControlUnknown();

    // Displays all physical drives
    // To avoid duplicate loading, use AutoInitialLoad = False in
    // property page
    m_vDir1->ControlStyle = styleSftDirectoryComboBoxDetailList;
    m_vDir1->TopMostFolderSpecial = specialSftDirectoryMyComputer;
    m_vDir1->Headers->Style = headersSftDirectoryButton;
    m_vDir1->Column[contentsSftDirectoryName]->HeaderText = "Drives";

    return TRUE;
}

void CFilteringDlg::OnFilteringSftDirectory1(LPDISPATCH FAR* Folder, BOOL FAR* RemoveFolder)
{
    ISftDirectoryFolderPtr pFolder(*Folder);

    // This filters out folders such as "Shared Documents", "Control Panel", which
    // are part of "My Computer"
    if (pFolder->Type >= typeSftDirectory_Computer_Drive35 && pFolder->Type <= typeSftDirectory_Computer_Other)
        ; // OK, add this to the control contents
    else
        *RemoveFolder = VARIANT_TRUE; // don't add this to the control contents
}

BEGIN_EVENTSINK_MAP(CFilteringDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CFilteringDlg)
    ON_EVENT(CFilteringDlg, IDC_SFTDIRECTORY1, 5 /* Filtering */, OnFilteringSftDirectory1, VTS_PDISPATCH VTS_PBOOL)
    //}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.