当我将单个文件从应用程序拖放到资源管理器时,将显示单个文件的图像。但是我想拖动多个文件并显示多个文件图像。有人可以帮忙吗?
Dragging a shell object, part 4: Adding a prettier drag icon
HRESULT GetDataObjectOfFileWithCuteIcon(HWND hwnd,LPCWSTR pszPath, IDataObject** ppdto)
{
HRESULT hr; /*= GetUIObjectOfFile(hwnd, pszPath,
IID_IDataObject, (void**)ppdto);*/
//if (SUCCEEDED(hr))
{
IDragSourceHelper* pdsh;
if (SUCCEEDED(CoCreateInstance(CLSID_DragDropHelper, NULL, CLSCTX_ALL,IID_IDragSourceHelper, (void**)& pdsh))) {
HIMAGELIST himl;
SHDRAGIMAGE sdi;
SIZE sz;
ZeroMemory(&sdi, sizeof(SHDRAGIMAGE));
sdi.crColorKey = CLR_NONE;
SHFILEINFOW sfi = { };
int UFlag = SHGFI_ICON | SHGFI_SMALLICON;
UFlag ^= SHGFI_SMALLICON;
//himl = (HIMAGELIST) SHGetFileInfoW(L"C:\\Users\\Venkatesh\\Desktop", 0, &sfi, sizeof(sfi), UFlag| SHGFI_SYSICONINDEX);
himl = (HIMAGELIST) SHGetFileInfoW(L"C:\\Users\\Venkatesh\\Desktop\\TestPage.pdf", 0, &sfi, sizeof(sfi), UFlag| SHGFI_SYSICONINDEX);
if (himl)
{
int cx, cy;
ImageList_GetIconSize(himl, &cx, &cy);
sdi.sizeDragImage.cx = cx;
sdi.sizeDragImage.cy = cy;
sdi.ptOffset.x = cx;
sdi.ptOffset.y = cy;
sdi.crColorKey = CLR_NONE;
sdi.hbmpDragImage = CreateBitmap(cx, cy, 1, 32, NULL);
HDC hdc = CreateCompatibleDC(NULL);
if (sdi.hbmpDragImage) {
// GetObject(sdi.hbmpDragImage, sizeof(BITMAP), &sdi.hbmpDragImage);
HBITMAP hbmPrev = (HBITMAP)SelectObject(hdc, (HGDIOBJ)sdi.hbmpDragImage);
ImageList_Draw(himl, sfi.iIcon, hdc, 0, 0, ILD_SCALE);
// ImageList_Draw(himl, sfi.iIcon, hdc, 0, 0, ILD_TRANSPARENT);
SelectObject(hdc, hbmPrev);
//if (CreateDragImage(pszPath, &sdi)) {
pdsh->InitializeFromBitmap(&sdi, *ppdto);
DeleteDC(hdc);
DeleteObject(sdi.hbmpDragImage);
}
//}
}
}
pdsh->Release();
}
hr = S_OK;
return hr;
}