How to Drag and Drop multiple files between Namesp

2019-08-24 02:09发布

问题:

I am working on a namespace extension project, I need to implement multiple files drag and drop between Namespace Extensions. I have used DragQueryFile API to find the the number of files. But Always this Function give a crash.

Could anyone help me by explaining how we can implement this multiple files Drag and drop.

Thanks, Robin

回答1:

Here is how I use it

void yourclass::OnDropFiles(HDROP hDropInfo)
{


    TCHAR lpszFile[MAX_PATH] = { 0 };
    UINT uFile = 0;

    uFile = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, NULL);
    if (uFile != 0)
    {
        for (int i = 0; i < uFile; i++)
        {
            lpszFile[0] = '\0';
            if (DragQueryFile(hDropInfo, i, lpszFile, MAX_PATH))
            {
                std::wstring directory;
                std::wstring filename;
                LVITEM lvi = { 0 };
                lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;

                SplitPath(lpszFile, directory, filename);

                lvi.iSubItem = 0;
                lvi.pszText = LPSTR_TEXTCALLBACK;
                lvi.cchTextMax = MAX_PATH;

                int n = m_wndFileList.InsertItem(&lvi);
                m_wndFileList.SetItemText(n, 0, filename.c_str());
                m_wndFileList.SetItemText(n, 1, directory.c_str());

            }
        }
    }
    DragFinish(hDropInfo);
    return;
    CDialogEx::OnDropFiles(hDropInfo);
}