public Boolean RefreshThumbnail(uint iconSize, out WTS_CACHEFLAGS flags) { ISharedBitmap bmp = null; WTS_CACHEFLAGS cacheFlags = WTS_CACHEFLAGS.WTS_DEFAULT; WTS_THUMBNAILID thumbId = new WTS_THUMBNAILID(); Boolean result = false; try { if (ThumbnailCache.GetThumbnail(this.shellItemNative, iconSize, WTS_FLAGS.WTS_FORCEEXTRACTION | WTS_FLAGS.WTS_SCALETOREQUESTEDSIZE, out bmp, cacheFlags, thumbId) != HResult.WTS_E_FAILEDEXTRACTION) { result = true; } } finally { if (bmp != null) { Marshal.ReleaseComObject(bmp); } } flags = cacheFlags; return(result); }
public HResult ExtractAndDrawThumbnail(IntPtr hdc, uint iconSize, out WTS_CACHEFLAGS flags, User32.RECT iconBounds, out bool retrieved, bool isHidden, bool isRefresh = false) { IThumbnailCache thumbCache = null; if (this.ComInterface != null) { var IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046"); var CLSID_LocalThumbnailCache = new Guid("50EF4544-AC9F-4A8E-B21B-8A26180DB13F"); IntPtr cachePointer; Ole32.CoCreateInstance(ref CLSID_LocalThumbnailCache, IntPtr.Zero, Ole32.CLSCTX.INPROC, ref IID_IUnknown, out cachePointer); thumbCache = (IThumbnailCache)Marshal.GetObjectForIUnknown(cachePointer); } var res = HResult.S_OK; ISharedBitmap bmp = null; flags = WTS_CACHEFLAGS.WTS_DEFAULT; var thumbId = default(WTS_THUMBNAILID); try { retrieved = false; res = thumbCache.GetThumbnail(this._Item.ComInterface, iconSize, isRefresh ? (WTS_FLAGS.WTS_FORCEEXTRACTION | WTS_FLAGS.WTS_SCALETOREQUESTEDSIZE) : (WTS_FLAGS.WTS_INCACHEONLY | WTS_FLAGS.WTS_SCALETOREQUESTEDSIZE), out bmp, flags, thumbId); var hBitmap = IntPtr.Zero; if (bmp != null) { bmp.GetSharedBitmap(out hBitmap); retrieved = true; int width; int height; Gdi32.ConvertPixelByPixel(hBitmap, out width, out height); Gdi32.NativeDraw(hdc, hBitmap, iconBounds.Left + (iconBounds.Right - iconBounds.Left - width) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - height) / 2, width, height, isHidden); Gdi32.DeleteObject(hBitmap); } } finally { if (bmp != null) { Marshal.ReleaseComObject(bmp); } } return(res); }
private static ImageData LoadThumbnail(string path, DateTime dtLastWriteTime, out Size sizeRaw, out Size sizeActual, out string toolTipText, out bool fCached) { sizeRaw = sizeActual = Size.Empty; toolTipText = null; fCached = false; IntPtr zero = IntPtr.Zero; IShellItem ppsi = null; ISharedBitmap ppvThumb = null; LocalThumbnailCache o = null; try { zero = PInvoke.ILCreateFromPath(path); if ((zero != IntPtr.Zero) && (PInvoke.SHCreateShellItem(IntPtr.Zero, null, zero, out ppsi) == 0)) { o = new LocalThumbnailCache(); IThumbnailCache cache2 = (IThumbnailCache)o; uint flags = 0; uint pOutFlags = 0; WTS_THUMBNAILID pThumbnailID = new WTS_THUMBNAILID(); uint cxyRequestedThumbSize = (uint)Math.Min(0x400, Math.Min(QTUtility.PreviewMaxWidth, QTUtility.PreviewMaxHeight)); if (cache2.GetThumbnail(ppsi, cxyRequestedThumbSize, flags, out ppvThumb, ref pOutFlags, ref pThumbnailID) == 0) { IntPtr ptr2; if ((pOutFlags & 2) == 2) { fCached = true; } if (ppvThumb.Detach(out ptr2) == 0) { Bitmap bmp = Image.FromHbitmap(ptr2); Size size = bmp.Size; sizeRaw = sizeActual = size; ImageData data = new ImageData(bmp, null, path, dtLastWriteTime, size, size); data.Thumbnail = true; try { toolTipText = data.TooltipText = ShellMethods.GetShellInfoTipText(zero, false); } catch { } return(data); } } } } catch (Exception exception) { QTUtility2.MakeErrorLog(exception, null); } finally { if (zero != IntPtr.Zero) { PInvoke.CoTaskMemFree(zero); } if (ppsi != null) { Marshal.ReleaseComObject(ppsi); } if (ppvThumb != null) { Marshal.ReleaseComObject(ppvThumb); } if (o != null) { Marshal.ReleaseComObject(o); } } return(null); }