How do you drag and drop files?

as in winamp or vlc player, how to make a file drag and drop? I want to say that I want to know what encoding is included in the application? I want to know for C ++

+5
source share
6 answers

In pure C / C ++ on Windows, start reading about the DragAcceptFiles and WM_DROPFILES functions . If you are using a more powerful C ++ library (Qt, Wx, etc.), check their respective documentation. This will help to know what you are using, more specifically.

In addition, this discussion may answer your question. If this is what you had in mind, please close this question.

+12

, , , ++; .


" ":

. , Windows #/. NET VB/.NET. ++, Delphi .. .

+1

com:

, public IDropTarget

. WM_CREATE

RegisterDragDrop(hwnd,static_cast<IDropTarget*>(pointer_to_your_class));

, :

virtual HRESULT STDMETHODCALLTYPE DragEnter( 
        /* [unique][in] */ __RPC__in_opt IDataObject *pDataObj,
        /* [in] */ DWORD grfKeyState,
        /* [in] */ POINTL pt,
        /* [out][in] */ __RPC__inout DWORD *pdwEffect) = 0;

virtual HRESULT STDMETHODCALLTYPE DragOver( 
    /* [in] */ DWORD grfKeyState,
    /* [in] */ POINTL pt,
    /* [out][in] */ __RPC__inout DWORD *pdwEffect) = 0;

virtual HRESULT STDMETHODCALLTYPE DragLeave( void) = 0;

virtual HRESULT STDMETHODCALLTYPE Drop( 
    /* [unique][in] */ __RPC__in_opt IDataObject *pDataObj,
    /* [in] */ DWORD grfKeyState,
    /* [in] */ POINTL pt,
    /* [out][in] */ __RPC__inout DWORD *pdwEffect) = 0;

, , - DragEnter , .

, IDropTarget , IUnknown MSDN.

IDataObject, :

FORMATETC fdrop = {CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};

if (SUCCEEDED(pDataObj->QueryGetData(&fdrop)) ){
    STGMEDIUM stgMedium = {0};
    stgMedium.tymed = TYMED_HGLOBAL;
    HRESULT hr = pDataObj->GetData(&fdrop, &stgMedium);
    if (SUCCEEDED(hr))
    {
        HGLOBAL gmem = stgMedium.hGlobal;
        HDROP hdrop = (HDROP)GlobalLock(gmem);
        UINT numOfFiles =  DragQueryFile( (HDROP) hdrop,
                            0xFFFFFFFF,
                           NULL,
                            0
                        );

        TCHAR buffer[MAX_PATH];
        for( int i=0;i<numOfFiles;i++ ){
            UINT charsCopied = DragQueryFile( (HDROP) hdrop,
                            i,
                           buffer,
                            MAX_PATH
                        );
            MessageBox(NULL,buffer,_T("Archivos a copiar: "),MB_OK);


        }
        // use str
        GlobalUnlock(gmem);


        /*TCHAR* str = (TCHAR*)GlobalLock(gmem);
        // use str
        GlobalUnlock(gmem);*/
        ::ReleaseStgMedium(&stgMedium);
    }

}

!

+1

COM Ole.

0

OLE/COM/ActiveX - :

  • mouse down, .
  • , . , , ( ).
  • : , drop , , .

. .

0

" ?"

: " wxWidgets."

0

All Articles