2 kobealone kobealone 于 2014.11.09 16:50 提问

C++ 实现从IE页面拖拽文件到本地

现在做了一个ATL 捕获IE页面上的拖拽事件,然后现在想通过ONDrag事件里,设定拖拽的数据源(页面上存着文件的路径),但是设定了数据源之后,无法保存到本地,求大神支援。

char szFileName[] = "D:\\user.txt";
    UINT uDropEffect;
    HGLOBAL hGblEffect;
    LPDWORD lpdDropEffect;
    DROPFILES stDrop;

    HGLOBAL hGblFiles;
    LPSTR lpData;

    uDropEffect = RegisterClipboardFormat(L"Preferred DropEffect");
    hGblEffect = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE,sizeof(DWORD));
    lpdDropEffect = (LPDWORD)GlobalLock(hGblEffect);
    *lpdDropEffect = DROPEFFECT_COPY;
    GlobalUnlock(hGblEffect);

    stDrop.pFiles = sizeof(DROPFILES);
    stDrop.pt.x = 0;
    stDrop.pt.y = 0;
    stDrop.fNC = FALSE;
    stDrop.fWide = FALSE;

    hGblFiles = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE,
        sizeof(DROPFILES)+strlen(szFileName)+2);
    lpData = (LPSTR)GlobalLock(hGblFiles);
    memcpy(lpData,&stDrop,sizeof(DROPFILES));
    strcpy(lpData+sizeof(DROPFILES),szFileName);
    GlobalUnlock(hGblFiles);
    OpenClipboard(NULL);
    EmptyClipboard();
    SetClipboardData(CF_HDROP,hGblFiles);
    SetClipboardData(uDropEffect,hGblEffect);
    CloseClipboard();

fmt.cfFormat = this->CF_PacsArticle;
    fmt.dwAspect = DVASPECT_CONTENT;
    fmt.lindex = -1;
    fmt.ptd = NULL;
    fmt.tymed = TYMED_HGLOBAL;

    //medium.hGlobal = hObject;
    medium.hGlobal = hGblFiles;
    medium.tymed = TYMED_HGLOBAL;
    medium.pUnkForRelease = NULL;
    //
    dobj = new CDataObject();
    if(dobj->SetData(&fmt, &medium, TRUE) == S_OK)
    {
        dsrc = new CDropSource();
        ret = ::DoDragDrop(dobj, dsrc, DROPEFFECT_COPY, &dwEffect);
}

1个回答

kobealone
kobealone   2014.11.10 13:48

自己顶 求大神 没人吗 着急

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!