现在的位置: 首页 > 综合 > 正文

DragSource Lib for BCB(DragDrop.h)

2013年01月25日 ⁄ 综合 ⁄ 共 5481字 ⁄ 字号 评论关闭
//---------------------------------------------------------------------------
// DragSource Lib.
// Copyright (c) 2006, 2007 by Mao yongjun
// All rights reserved
// Add "WINOLEAPI OleInitialize (LPVOID pvReserved)" before use DragDropLib on each thread
// Don't forget "WINOLEAPI OleUninitialize ()" on exit the thread
//---------------------------------------------------------------------------

#ifndef DragDropH
#define DragDropH
#include 
<oleidl.h>
#include 
<objidl.h>
#include 
<vector>
#include 
<string>

struct THDROP_Files :
    std::vector
<std::string>{
    
void *Create_HDROP() const;
}
;


struct TDropResult {
    DWORD Result;
    
/*
    * DRAGDROP_S_DROP
    *     The OLE drag-and-drop operation was successful.
    * DRAGDROP_S_CANCEL
    *     The OLE drag-and-drop operation was canceled.
    * E_UNSPEC
    *     Unexpected error occurred.
    
*/

    DWORD Effect;
    
/*
    * typedef enum tagDROPEFFECT
    * {
    *     DROPEFFECT_NONE   = 0,
    *     DROPEFFECT_COPY   = 1,
    *     DROPEFFECT_MOVE   = 2,
    *     DROPEFFECT_LINK   = 4,
    *     DROPEFFECT_SCROLL = 0x80000000
    * }DROPEFFECT;
    
*/

}
;
//---------------------------------------------------------------------------
TDropResult DoDragDrop(FORMATETC *fmtetc, STGMEDIUM *stgmeds,UINT count=1,
        DWORD dwOKEffect
=DROPEFFECT_COPY|DROPEFFECT_MOVE);  //Drag fms,
TDropResult DoDragDrop(CLIPFORMAT ctFormat,DWORD tymed,void *hStorage,
        DWORD dwOKEffect
=DROPEFFECT_COPY|DROPEFFECT_MOVE);  //Drag simple type, hStorage will be freed
TDropResult DoDragDrop(char *szText,
        DWORD dwOKEffect
=DROPEFFECT_COPY|DROPEFFECT_MOVE);  //Drag Text
TDropResult DoDragDropURL(char *URL,
        DWORD dwOKEffect
=DROPEFFECT_COPY|DROPEFFECT_MOVE|DROPEFFECT_LINK);  //Drag URL
TDropResult DoDragDrop(wchar_t *wszText,
        DWORD dwOKEffect
=DROPEFFECT_COPY|DROPEFFECT_MOVE);  //Drag Unicode Text
TDropResult DoDragDrop(HBITMAP hBitmap,
        DWORD dwOKEffect
=DROPEFFECT_COPY|DROPEFFECT_MOVE);  //Drag Bitmap
TDropResult DoDragDrop(const THDROP_Files &files,
        DWORD dwOKEffect
=DROPEFFECT_COPY|DROPEFFECT_MOVE|DROPEFFECT_LINK);  //Drag Files

HRESULT CreateDataObject (FORMATETC 
*fmtetc, STGMEDIUM *stgmeds, UINT count, IDataObject **ppDataObject);
HRESULT CreateEnumFormatEtc (UINT cfmt, FORMATETC 
*afmt, IEnumFORMATETC **ppEnumFormatEtc);
HANDLE MemToHandle (
void *pMem, int nSize);
//----------------TDropSource-----------------------------------------------------------
class TDropSource
    :
public IDropSource
{
private:
    ULONG _iRefCount;
public:
    
// IUnknown members
    HRESULT __stdcall QueryInterface(REFIID iid, void **ppv);
    ULONG __stdcall AddRef(
voidreturn ++_iRefCount; }
    ULONG __stdcall Release(
voidif(--_iRefCount==0){delete thisreturn 0;} return _iRefCount; }

    
// IDropSource
    HRESULT __stdcall QueryContinueDrag(BOOL fEscapePressed,DWORD grfKeyState);
    HRESULT __stdcall GiveFeedback(DWORD dwEffect);
    
    
//
    TDropSource():_iRefCount(1){;}
    
virtual ~TDropSource() {;}
}
;

//----------------TDataObject-----------------------------------------------------------
class TDataObject : public IDataObject
{
public:
    
// IUnknown members
    HRESULT __stdcall QueryInterface (REFIID iid, void ** ppv);
    ULONG   __stdcall AddRef (
voidreturn ++_iRefCount; }
    ULONG   __stdcall Release (
void)  if(--_iRefCount==0){delete this;  return 0;} return _iRefCount; }

    
// IDataObject members
    HRESULT __stdcall GetData (FORMATETC *pFormatEtc, STGMEDIUM *pStgMedium);
    HRESULT __stdcall QueryGetData (FORMATETC 
*pFormatEtc);
    HRESULT __stdcall EnumFormatEtc (DWORD dwDirection, IEnumFORMATETC 
**ppEnumFormatEtc);

    HRESULT __stdcall GetDataHere (FORMATETC 
*pFormatEtc, STGMEDIUM *pmedium){
        
return DATA_E_FORMATETC;
    }

    HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC 
*pFormatEct, FORMATETC *pFormatEtcOut){
        
// Apparently we have to set this field to NULL even though we don't do anything else
        pFormatEtcOut->ptd = NULL;
        
return E_NOTIMPL;
    }

    HRESULT __stdcall SetData (FORMATETC 
*pFormatEtc, STGMEDIUM *pMedium,  BOOL fRelease){
        
return E_NOTIMPL;
    }

    HRESULT __stdcall DAdvise (FORMATETC 
*pFormatEtc, DWORD advf, IAdviseSink *, DWORD *){
        
return OLE_E_ADVISENOTSUPPORTED;
    }

    HRESULT __stdcall DUnadvise (DWORD dwConnection)
{
        
return OLE_E_ADVISENOTSUPPORTED;
    }

    HRESULT __stdcall EnumDAdvise (IEnumSTATDATA 
**ppEnumAdvise){
        
return OLE_E_ADVISENOTSUPPORTED;
    }


    
// Constructor / Destructor
    TDataObject():_iRefCount(1{;}
    
virtual ~TDataObject (){;}

    
void Add(FORMATETC *fmtetc, STGMEDIUM *stgmeds, UINT count);
    
void Add(CLIPFORMAT ctFormat,DWORD tymed,void *hStorage);
    size_t size()
{return _pFormatEtc.size();}
    
bool empty(){return _pFormatEtc.empty();}
    
void Clear();
    
void ClearAndRelease();

private:
    ULONG _iRefCount;
    std::vector
<FORMATETC> _pFormatEtc;
    std::vector
<STGMEDIUM> _pStgMedium;
    
int LookupFormatEtc(FORMATETC *pFormatEtc);
}
;

//----------------TEnumFormatEtc-----------------------------------------------------------
class TEnumFormatEtc : public IEnumFORMATETC
{
public:
    
// IUnknown members
    HRESULT __stdcall  QueryInterface (REFIID iid, void ** ppv)
    
{
        
if((iid==IID_IUnknown)||(iid==IID_IEnumFORMATETC))
        
{
            
*ppv=this;
            AddRef();
            
return S_OK;
        }

        
else
        
{
            
*ppv=NULL;
            
return E_NOINTERFACE;
        }

    }

抱歉!评论已关闭.