1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
HBITMAP GetThumbnail(wstring File)
{
wstring Folder,FileName;
int Pos = File.find_last_of(L"\\");
Folder = File.substr(0,Pos);
FileName = File.substr(Pos+1);
IShellFolder* pDesktop = NULL;
IShellFolder* pSub = NULL;
IExtractImage* pIExtract = NULL;
LPITEMIDLIST pidl = NULL;
HRESULT hr;
hr = SHGetDesktopFolder(&pDesktop);
if(FAILED(hr)) return NULL;
hr = pDesktop->ParseDisplayName(NULL, NULL, (LPWSTR)Folder.c_str(), NULL, &pidl, NULL);
if(FAILED(hr)) return NULL;
hr = pDesktop->BindToObject(pidl, NULL, IID_IShellFolder, (void**)&pSub);
if(FAILED(hr)) return NULL;
hr = pSub->ParseDisplayName(NULL, NULL, (LPWSTR)FileName.c_str(), NULL, &pidl, NULL);
if(FAILED(hr)) return NULL;
hr = pSub ->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST *)&pidl, IID_IExtractImage, NULL, (void**)& pIExtract);
if(FAILED(hr)) return NULL;
SIZE size;
size.cx =300;
size.cy =300;
DWORD dwFlags = IEIFLAG_ORIGSIZE | IEIFLAG_QUALITY;
HBITMAP hThumbnail = NULL;
// Set up the options for the image
OLECHAR pathBuffer[MAX_PATH];
hr = pIExtract->GetLocation(pathBuffer, MAX_PATH, NULL, &size,32, &dwFlags);
// Get the image
hr = pIExtract ->Extract(&hThumbnail);
pDesktop->Release();
pSub->Release();
return hThumbnail;
}
| |