static HRESULT DecodeImageFromThumbCache(IShellItem* pShellItem, HBITMAP &thumbnail, int cXY) { // Read the bitmap from the thumbnail cache IThumbnailCache* pThumbCache; HRESULT hr = CoCreateInstance(CLSID_LocalThumbnailCache, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pThumbCache)); if (SUCCEEDED(hr)) { ISharedBitmap* pBitmap = NULL; hr = pThumbCache->GetThumbnail(pShellItem, cXY, WTS_EXTRACT | WTS_SCALETOREQUESTEDSIZE, &pBitmap, NULL, NULL); if (SUCCEEDED(hr) && pBitmap != NULL) { hr = pBitmap->GetSharedBitmap(&thumbnail); if (!SUCCEEDED(hr)) { LOG_ERROR("Failed to get shared bitmap, result = %d", hr); } else if (thumbnail == NULL) { LOG_ERROR("Failed to get shared bitmap, thumbnail == NULL"); } } else { LOG_ERROR("Failed to get thumbnail, result = %d", hr); } pThumbCache->Release(); } else { LOG_ERROR("Failed to create instance of IThumbnailCache, result = %d", hr); } return hr; }
HRESULT CMainWindow::DecodeImageFromThumbCache( IShellItem *pShellItem, ID2D1Bitmap **ppBitmap ) { const UINT THUMB_SIZE = 256; // Read the bitmap from the thumbnail cache IThumbnailCache *pThumbCache; HRESULT hr = CoCreateInstance( CLSID_LocalThumbnailCache, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pThumbCache) ); if (SUCCEEDED(hr)) { ISharedBitmap *pBitmap; hr = pThumbCache->GetThumbnail( pShellItem, THUMB_SIZE, WTS_SCALETOREQUESTEDSIZE, &pBitmap, NULL, NULL ); if (SUCCEEDED(hr)) { HBITMAP hBitmap; hr = pBitmap->GetSharedBitmap( &hBitmap ); if (SUCCEEDED(hr)) { // Create a WIC bitmap from the shared bitmap IWICImagingFactory *pFactory; hr = CoCreateInstance( CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFactory) ); if (SUCCEEDED(hr)) { IWICBitmap *pWICBitmap; hr = pFactory->CreateBitmapFromHBITMAP( hBitmap, NULL, WICBitmapIgnoreAlpha, &pWICBitmap ); if (SUCCEEDED(hr)) { // Create a D2D bitmap from the WIC bitmap hr = m_pRenderTarget->CreateBitmapFromWicBitmap( pWICBitmap, NULL, ppBitmap ); pWICBitmap->Release(); } pFactory->Release(); } } pBitmap->Release(); } pThumbCache->Release(); } return hr; }