コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }