Board index » cppbuilder » Drag&Drop from the Desktop

Drag&Drop from the Desktop

Hi !

I'm trying to drag files from the desktop in one of my listviews. It is no
problem when I perform a Drag&Drop operation from one listview to another
but from the desktop ? Why doesn't it work ?

Thanx, Florian

 

Re:Drag&Drop from the Desktop


Because most likely, you are using the Drag&Drop features already built into
your ListViews, right?  Those are implemented and controlled entirely by the
VCL specifically for the task of drag&dropping between VCL components within
the same application.

However, the kind of Drag&Drop you are asking about and need to use is the
one that is controlled by the OS.  As such, you must implement it yourself
manually.  Look in the Win32 API reference (win32.hlp or
http://msdn.microsoft.com/search) at the RegisterDragDrop() and
RevokeDragDrop() functions, and implementing the IDropTarget interface.

Gambit

Quote
"Florian Pose" <flor...@maculaweb.de> wrote in message

news:3a341543$1_1@dnews...
Quote
> I'm trying to drag files from the desktop in one of my listviews. It is no
> problem when I perform a Drag&Drop operation from one listview to another
> but from the desktop ? Why doesn't it work ?

Re:Drag&Drop from the Desktop


Hey, Thanks !

Now I know, that I have to register my ListView as an OLE drop target. But I
found no proper Informaition how to implement the IDropTarget neither in the
API help nor in MSDN ... :-(
Moreover the call of the function RegisterDragDrop returns an unknown
value...

IDroptarget *Droptarget;
[...]
RegisterDragDrop(ListView1,Droptarget);

Can you help me further ?

Thanx a lot, Florian

Remy Lebeau <gambi...@gte.net> schrieb in im Newsbeitrag:
9119qm$ks...@bornews.inprise.com...

Quote
> Because most likely, you are using the Drag&Drop features already built
into
> your ListViews, right?  Those are implemented and controlled entirely by
the
> VCL specifically for the task of drag&dropping between VCL components
within
> the same application.

> However, the kind of Drag&Drop you are asking about and need to use is the
> one that is controlled by the OS.  As such, you must implement it yourself
> manually.  Look in the Win32 API reference (win32.hlp or
> http://msdn.microsoft.com/search) at the RegisterDragDrop() and
> RevokeDragDrop() functions, and implementing the IDropTarget interface.

> Gambit

> "Florian Pose" <flor...@maculaweb.de> wrote in message
> news:3a341543$1_1@dnews...

> > I'm trying to drag files from the desktop in one of my listviews. It is
no
> > problem when I perform a Drag&Drop operation from one listview to
another
> > but from the desktop ? Why doesn't it work ?

Re:Drag&Drop from the Desktop


give a look here:
http://bcbcaq.freeservers.com/project_DD.html

    rony.

Re:Drag&Drop from the Desktop


IDropTarget is an interface, not a standalone class, so you have to write
your own class that inherits from IDropTarget, sorry for not making that
clearer before.
class MyDropTarget : public IDropTarget
{
public:
    HRESULT DragEnter(IDataObject*, DWORD, POINTL, DWORD*);
    HRESULT DragOver(DWORD, POINTL, DWORD*);
    HRESULT DragLeave(void);
    HRESULT Drop(IDataObject*, DWORD, POINTL, DWORD*);
 };

HRESULT MyDropTarget::DragEnter(IDataObject *pDataObject, DWORD grfKeyState,
POINTL pt, DWORD *pdwEffect)
{
    // your code

Quote
}

HRESULT MyDropTarget::DragOver(DWORD grfKeyState, POINTL pt, DWORD
*pdwEffect)
{
    // your code

Quote
}

HRESULT MyDropTarget::DragLeave(void)
{
    // your code

Quote
}

HRESULT MyDropTarget::Drop(IDataObject *pDataObject, DWORD grfKeyState,
POINTL pt, DWORD *pdwEffect)
{
    // your code

Quote
}

MyDropTarget *MDT;
[...]
RegisterDragDrop(ListView1->Handle, MDT);

Gambit

Quote
Florian Pose <flor...@maculaweb.de> wrote in message

news:3a34a912$1_1@dnews...
Quote
> Now I know, that I have to register my ListView as an OLE drop target. But
I
> found no proper Informaition how to implement the IDropTarget neither in
the
> API help nor in MSDN ... :-(
> Moreover the call of the function RegisterDragDrop returns an unknown
> value...

Re:Drag&Drop from the Desktop


Aaah ! Now I understood it !

Thanx a lot !

Best regards,

Florian

Re:Drag&Drop from the Desktop


Sorry, that I'm asking once more:
I declared the 4 Functions of the IDropTarget...
What can it be, if my RegisterDragDrop call produces an unknown error ?
Is there something I forgot to declare in the derives class ?

Thank you,
 Florian

Remy Lebeau <gambi...@gte.net> schrieb in im Newsbeitrag:
91332t$p...@bornews.inprise.com...

Quote
> IDropTarget is an interface, not a standalone class, so you have to write
> your own class that inherits from IDropTarget, sorry for not making that
> clearer before.

> class MyDropTarget : public IDropTarget
> {
> public:
>     HRESULT DragEnter(IDataObject*, DWORD, POINTL, DWORD*);
>     HRESULT DragOver(DWORD, POINTL, DWORD*);
>     HRESULT DragLeave(void);
>     HRESULT Drop(IDataObject*, DWORD, POINTL, DWORD*);
>  };

> HRESULT MyDropTarget::DragEnter(IDataObject *pDataObject, DWORD
grfKeyState,
> POINTL pt, DWORD *pdwEffect)
> {
>     // your code
> }

> HRESULT MyDropTarget::DragOver(DWORD grfKeyState, POINTL pt, DWORD
> *pdwEffect)
> {
>     // your code
> }

> HRESULT MyDropTarget::DragLeave(void)
> {
>     // your code
> }

> HRESULT MyDropTarget::Drop(IDataObject *pDataObject, DWORD grfKeyState,
> POINTL pt, DWORD *pdwEffect)
> {
>     // your code
> }

> MyDropTarget *MDT;
> [...]
> RegisterDragDrop(ListView1->Handle, MDT);

> Gambit

> Florian Pose <flor...@maculaweb.de> wrote in message
> news:3a34a912$1_1@dnews...
> > Now I know, that I have to register my ListView as an OLE drop target.
But
> I
> > found no proper Informaition how to implement the IDropTarget neither in
> the
> > API help nor in MSDN ... :-(
> > Moreover the call of the function RegisterDragDrop returns an unknown
> > value...

Re:Drag&Drop from the Desktop


Does your code call CoInitialize() or OleInitialize() anywhere before
calling RegisterDragDrop()?

The only other thing I can think of is to also add the following functions
to your TDropTarget-derived class as well, and see if they help at all:

class MyDropTarget : public IDropTarget
{
private:
    DWORD cRefs;
public:
    CContextMenuHandler();

    // the following three functions come from the IUnknown interface
    // which IDropTarget is derived from

    STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObj);
    STDMETHODIMP_(DWORD) AddRef(void);
    STDMETHODIMP_(DWORD) Release(void);

Quote
};

CContextMenuHandler::CContextMenuHandler()
{
    cRefs = 0;

Quote
}

STDMETHODIMP MyDropTarget::QueryInterface(REFIID riid, LPVOID *ppv)
{
    *ppv = NULL;

    if(IsEqualIID(riid, IID_IUnknown))
        *ppv = this;
    else if(IsEqualIID(riid, IID_IDropTarget))
        *ppv = (IDropTarget*)this;

    if (*ppv == NULL)
        return E_NOINTERFACE;

    ((LPUNKNOWN)*ppv)->AddRef();
    return NOERROR;

Quote
}

STDMETHODIMP_(DWORD) MyDropTarget::AddRef(void)
{
    return ++cRefs;

Quote
}

STDMETHODIMP_(DWORD) MyDropTarget::Release(void)
{
    if (--cRefs != 0)
        return cRefs;

    delete this;
    return 0;

Quote
}

Gambit

Quote
"Florian Pose" <flor...@maculaweb.de> wrote in message

news:3a360ca2$1_2@dnews...
Quote
> Sorry, that I'm asking once more:
> I declared the 4 Functions of the IDropTarget...
> What can it be, if my RegisterDragDrop call produces an unknown error ?

> Is there something I forgot to declare in the derives class ?

Re:Drag&Drop from the Desktop


THANKS !! THAT WAS IT !

Now it works !

Best regards, Florian

Remy Lebeau <gambi...@gte.net> schrieb in im Newsbeitrag:
916ptn$r...@bornews.inprise.com...

Quote
> Does your code call CoInitialize() or OleInitialize() anywhere before
> calling RegisterDragDrop()?

> The only other thing I can think of is to also add the following functions
> to your TDropTarget-derived class as well, and see if they help at all:

> class MyDropTarget : public IDropTarget
> {
> private:
>     DWORD cRefs;
> public:
>     CContextMenuHandler();

>     // the following three functions come from the IUnknown interface
>     // which IDropTarget is derived from

>     STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObj);
>     STDMETHODIMP_(DWORD) AddRef(void);
>     STDMETHODIMP_(DWORD) Release(void);
> };

> CContextMenuHandler::CContextMenuHandler()
> {
>     cRefs = 0;
> }

> STDMETHODIMP MyDropTarget::QueryInterface(REFIID riid, LPVOID *ppv)
> {
>     *ppv = NULL;

>     if(IsEqualIID(riid, IID_IUnknown))
>         *ppv = this;
>     else if(IsEqualIID(riid, IID_IDropTarget))
>         *ppv = (IDropTarget*)this;

>     if (*ppv == NULL)
>         return E_NOINTERFACE;

>     ((LPUNKNOWN)*ppv)->AddRef();
>     return NOERROR;
> }

> STDMETHODIMP_(DWORD) MyDropTarget::AddRef(void)
> {
>     return ++cRefs;
> }

> STDMETHODIMP_(DWORD) MyDropTarget::Release(void)
> {
>     if (--cRefs != 0)
>         return cRefs;

>     delete this;
>     return 0;
> }

> Gambit

> "Florian Pose" <flor...@maculaweb.de> wrote in message
> news:3a360ca2$1_2@dnews...
> > Sorry, that I'm asking once more:
> > I declared the 4 Functions of the IDropTarget...
> > What can it be, if my RegisterDragDrop call produces an unknown error ?

> > Is there something I forgot to declare in the derives class ?

Other Threads