Hide

SftDirectory 3.5 - ActiveX File/Folder Control

Display
Print

OleDrag Sample (C++)

This sample illustrates SftDirectory as a drop target (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, 31 /* OLEDragDrop */, OnOLEDragDropSftDirectory1, VTS_PDISPATCH VTS_PDISPATCH VTS_PI4 VTS_PI2 VTS_PI2 VTS_PR4 VTS_PR4 VTS_PBOOL)
    ON_EVENT(COLEDragDlg, IDC_SFTDIRECTORY1, 32 /* OLEDragOver */, OnOLEDragOverSftDirectory1, VTS_PDISPATCH VTS_PDISPATCH VTS_PI4 VTS_PI2 VTS_PI2 VTS_PR4 VTS_PR4 VTS_PI4 VTS_PBOOL)
    //}}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->OLEDropMode = OLEDropSftControlManual;
    m_vDir1->AutoExpandDragDrop = VARIANT_TRUE;
    return TRUE;
}

void COLEDragDlg::OnOLEDragDropSftDirectory1(LPDISPATCH FAR* Data, LPDISPATCH FAR* Folder, long FAR* Effect, short FAR* Button, short FAR* Shift, float FAR* x, float FAR* y, BOOL FAR* DefaultHandling)
{
    IVDMDataObjectPtr pData(*Data);
    ISftDirectoryFolderPtr pFolder(*Folder);

    if (pData->GetFormat(sftCFFiles)) {
        int i;
        for (i = 1 ; i <= pData->Files->Count ; ++i) {
            CString str;
            CString strName((LPCWSTR)pData->Files->Item[i]);
            str.Format(_T("\"%s\" being dropped."), strName);
            MessageBox(str);
            // perform your own processing here
        }
    } else {
        // some other format
    }
    // make sure the control doesn't perform its usual default handling of
    // the files (copy/move, etc.)
    *DefaultHandling = VARIANT_FALSE;
}

void COLEDragDlg::OnOLEDragOverSftDirectory1(LPDISPATCH FAR* Data, LPDISPATCH FAR* Folder, long FAR* Effect, short FAR* Button, short FAR* Shift, float FAR* x, float FAR* y, long FAR* State, BOOL FAR* DefaultHandling)
{
    IVDMDataObjectPtr pData(*Data);
    ISftDirectoryFolderPtr pFolder(*Folder);

    *Effect = 0;
    if (pData->GetFormat(sftCFFiles)) {
        if (pFolder != NULL) {
            // we'll accept anything
            *Effect = 3; // vbDropEffectCopy | vbDropEffectMove
        }
    }
    // make sure the control doesn't perform its usual default handling of
    // the files (copy/move, etc.)
    *DefaultHandling = VARIANT_FALSE;
}

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