DragSource Lib for BCB(DragDrop.h)

本文介绍了一个名为 DragDropLib 的库,该库用于简化 Windows 平台上拖放操作的实现。文章详细解释了如何初始化库、创建拖放源对象及数据对象,并提供了多种拖放数据类型的示例,如文本、URL 和文件等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//---------------------------------------------------------------------------
// 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;
        }

    }

    ULONG   __stdcall AddRef (
voidreturn ++_iRefCount; }
    ULONG   __stdcall Release (
void)  if(--_iRefCount==0){delete this;  return 0;} return _iRefCount; }

    
// IEnumFormatEtc members
    HRESULT __stdcall  Next  (ULONG celt, FORMATETC * rgelt, ULONG * pceltFetched);
    HRESULT __stdcall  Skip  (ULONG celt)
    
{
        _nIndex 
+= celt;
        
return (_nIndex <= _nNumFormats) ? S_OK : S_FALSE;
    }

    HRESULT __stdcall  Reset (
void)
    
{
        _nIndex 
= 0;
        
return S_OK;
    }

    HRESULT __stdcall  Clone (IEnumFORMATETC 
** ppEnumFormatEtc)
    
{
        HRESULT hResult;
        hResult 
= CreateEnumFormatEtc(_nNumFormats, _pFormatEtc, ppEnumFormatEtc);
        
if(hResult == S_OK)
        
{
            ((TEnumFormatEtc 
*)*ppEnumFormatEtc)->_nIndex = _nIndex;
        }

        
return hResult;
    }


    
// Construction / Destruction
    TEnumFormatEtc(FORMATETC *pFormatEtc, ULONG nNumFormats);
    
~TEnumFormatEtc();

private:
    LONG        _iRefCount;        
// Reference count for this COM interface
    ULONG       _nIndex;           // current enumerator index
    ULONG       _nNumFormats;      // number of FORMATETC members
    FORMATETC * _pFormatEtc;       // array of FORMATETC objects
}
;
//---------------------------------------------------------------------------
#endif
 
 
OpenJDK 64-Bit Server VM warning: Archived non-system classes are disabled because the java.system.class.loader property is specified (value = &quot;com.intellij.util.lang.PathClassLoader&quot;). To use archived non-system classes, this property must not be set 2025-04-01 09:15:16,701 [ 151] SEVERE - #c.i.u.s.SvgCacheManager - Cannot create SvgCacheManager kotlinx.coroutines.JobCancellationException: Parent job is Cancelling; job=UndispatchedCoroutine{Cancelling}@706d4d07 Caused by: java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it. at java.desktop/java.awt.dnd.DragSource.getDefaultDragSource(DragSource.java:226) at com.intellij.platform.ide.bootstrap.UiKt$scheduleUpdateFrameClassAndWindowIconAndPreloadSystemFonts$1$3.invokeSuspend(ui.kt:255) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104) at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714) at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDis
最新发布
04-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值