public HResult ExtractAndDrawThumbnail(IntPtr hdc, uint iconSize, out WTS_CACHEFLAGS flags, User32.RECT iconBounds, out bool retrieved, bool isHidden, bool isRefresh = false)
{
HResult res = HResult.S_OK;
ISharedBitmap bmp = null;
flags = WTS_CACHEFLAGS.WTS_DEFAULT;
WTS_THUMBNAILID thumbId = new WTS_THUMBNAILID();
try
{
retrieved = false;
res = ThumbnailCache.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);
IntPtr 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;
}