Hide

SftDirectory 3.5 - ActiveX File/Folder Control

Display
Print

OleDrag2 Sample (C++)

This sample illustrates SftDirectory as a drag source (drag & drop).

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

// OLEDragDlg.cpp : implementation file
//

#include "stdafx.h"
#include "OLEDrag.h"
#include "OLEDragDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// COLEDragDlg dialog

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

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

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

BEGIN_EVENTSINK_MAP(COLEDragDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(COLEDragDlg)
    ON_EVENT(COLEDragDlg, IDC_SFTDIRECTORY1, 4 /* DragStarting */, OnDragStartingSftDirectory1, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
    ON_EVENT(COLEDragDlg, IDC_SFTDIRECTORY1, 35 /* OLEStartDrag */, OnOLEStartDragSftDirectory1, VTS_PDISPATCH VTS_PI4)
    ON_EVENT(COLEDragDlg, IDC_SFTDIRECTORY1, 34 /* OLESetData */, OnOLESetDataSftDirectory1, VTS_PDISPATCH VTS_PI2)
    //}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

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

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

    m_vDir1 = m_Dir1.GetControlUnknown();

    m_vDir1->OLEDragMode = OLEDragSftControlManual;

    return TRUE;
}

void COLEDragDlg::OnDragStartingSftDirectory1(short Button, short Shift, long xPos, long yPos)
{
    ISftDirectoryFolderPtr pFolder;

    pFolder = m_vDir1->CurrentFolder;
    if (pFolder)
        m_vDir1->OLEDrag(VARIANT_FALSE, VARIANT_TRUE, -1, -1);
}

void COLEDragDlg::OnOLEStartDragSftDirectory1(LPDISPATCH FAR* Data, long FAR* AllowedEffects)
{
    IVDMDataObjectPtr pData(*Data);

    pData->Clear();
    pData->SetData(_variant_t(), _variant_t((short) sftCFText));
    *AllowedEffects = 1; //vbDropEffectCopy
}

void COLEDragDlg::OnOLESetDataSftDirectory1(LPDISPATCH FAR* Data, short FAR* Format)
{
    IVDMDataObjectPtr pData(*Data);

    if (*Format == sftCFText) {
        CString str;
        CString strName = (LPCWSTR) m_vDir1->CurrentFolder->Name;
        str.Format(_T("We're dragging a text string - \"%s\" - drop it in Write, Word (for example)"), strName);
        pData->SetData(_variant_t((LPCTSTR) str), _variant_t((short) sftCFText));
    }
}

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