Hide

SftDirectory 3.5 - ActiveX File/Folder Control

Display
Print

UserContents Sample (C++)

This sample illustrates adding user-defined columns.

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

// UserContentsDlg.cpp : implementation file
//

#include "stdafx.h"
#include "UserContents.h"
#include "UserContentsDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CUserContentsDlg dialog

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

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

BEGIN_MESSAGE_MAP(CUserContentsDlg, CDialog)
    //{{AFX_MSG_MAP(CUserContentsDlg)
    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 CUserContentsDlg::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 CUserContentsDlg::OnQueryDragIcon()
{
    return (HCURSOR) m_hIcon;
}

BEGIN_EVENTSINK_MAP(CUserContentsDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CUserContentsDlg)
    ON_EVENT(CUserContentsDlg, IDC_SFTDIRECTORY1, 25 /* UserContents */, OnUserContentsSftDirectory1, VTS_DISPATCH VTS_I4 VTS_PBSTR)
    //}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

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

    SetIcon(m_hIcon, TRUE);
    SetIcon(m_hIcon, FALSE);

    m_vDir1 = m_Dir1.GetControlUnknown();

    m_vDir1->ColumnCount = 2;
    m_vDir1->ShowFiles = VARIANT_FALSE;
    m_vDir1->GridStyle = gridSftDirectoryBoth;
    m_vDir1->Headers->Style = headersSftDirectoryButton;
    m_vDir1->ColumnEntry[0]->HeaderText = _T("Folder");
    m_vDir1->ColumnEntry[1]->HeaderText = _T("Full Path");
    m_vDir1->ColumnEntry[1]->Contents = contentsSftDirectoryUser1;
    m_vDir1->Reload(VARIANT_FALSE, VARIANT_FALSE);

    return TRUE;  // return TRUE  unless you set the focus to a control
}

void CUserContentsDlg::OnUserContentsSftDirectory1(LPDISPATCH Folder, long Contents, BSTR FAR* UserString)
{
    ISftDirectoryFolderPtr pFolder = Folder;

    if (Contents == contentsSftDirectoryUser1) {
        *UserString = SysAllocString(pFolder->Path);
    }
}

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