Exemple #1
0
        private bool GetThumbnail(string file, IntPtr pidl, IShellFolder item, int width, int height)
        {
            IntPtr        hBmp         = IntPtr.Zero;
            IExtractImage extractImage = null;

            try
            {
                string pidlPath = PathFromPidl(pidl);
                if (Path.GetFileName(pidlPath).ToUpper().Equals(Path.GetFileName(file).ToUpper()))
                {
                    IUnknown iunk            = null;
                    int      prgf            = 0;
                    Guid     iidExtractImage = new Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1");
                    item.GetUIObjectOf(IntPtr.Zero, 1, ref pidl, ref iidExtractImage, out prgf, ref iunk);
                    extractImage = (IExtractImage)iunk;

                    if (extractImage != null)
                    {
                        SIZE sz = new SIZE();
                        sz.cx = width;
                        sz.cy = height;
                        StringBuilder location             = new StringBuilder(260, 260);
                        int           priority             = 0;
                        int           requestedColourDepth = 32;
                        EIEIFLAG      flags  = EIEIFLAG.IEIFLAG_ASPECT | EIEIFLAG.IEIFLAG_SCREEN;
                        int           uFlags = (int)flags;

                        extractImage.GetLocation(location, location.Capacity, ref priority, ref sz, requestedColourDepth, ref uFlags);

                        extractImage.Extract(out hBmp);
                        if (hBmp != IntPtr.Zero)
                        {
                            thumbNail = System.Drawing.Bitmap.FromHbitmap(hBmp);
                        }

                        Marshal.ReleaseComObject(extractImage);
                        extractImage = null;
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                if (hBmp != IntPtr.Zero)
                {
                    UnmanagedMethods.DeleteObject(hBmp);
                }
                if (extractImage != null)
                {
                    Marshal.ReleaseComObject(extractImage);
                }
                throw ex;
            }
        }
        private bool _getThumbNail(string file, IntPtr pidl, IShellFolder item)
        {
            IntPtr        hBmp         = IntPtr.Zero;
            IExtractImage extractImage = null;

            IntPtr[] pidl_array = new IntPtr[] { pidl };
            try
            {
                string pidlPath = PathFromPidl(pidl);
                if (Path.GetFileName(pidlPath).ToUpper().Equals(Path.GetFileName(file).ToUpper()))
                {
                    object iunk            = null;
                    Guid   iidExtractImage = new Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1");
                    item.GetUIObjectOf(IntPtr.Zero, 1, pidl_array, ref iidExtractImage, IntPtr.Zero, out iunk);
                    extractImage = (IExtractImage)iunk;
                    if (extractImage != null)
                    {
                        Console.WriteLine("Got an IExtractImage object!");
                        SIZE sz = new SIZE();
                        sz.cx = DesiredSize.Width;
                        sz.cy = DesiredSize.Height;
                        StringBuilder location             = new StringBuilder(260, 260);
                        int           priority             = 0;
                        int           requestedColourDepth = 32;
                        EIEIFLAG      flags  = EIEIFLAG.IEIFLAG_ASPECT | EIEIFLAG.IEIFLAG_SCREEN;
                        int           uFlags = (int)flags;
                        extractImage.GetLocation(location, location.Capacity, ref priority, ref sz, requestedColourDepth, ref uFlags);
                        extractImage.Extract(ref hBmp);
                        if (hBmp != IntPtr.Zero)
                        {
                            _thumbNail = Bitmap.FromHbitmap(hBmp);
                        }
                        Marshal.ReleaseComObject(extractImage);
                        extractImage = null;
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                if (hBmp != IntPtr.Zero)
                {
                    UnmanagedMethods.DeleteObject(hBmp);
                }
                if (extractImage != null)
                {
                    Marshal.ReleaseComObject(extractImage);
                }



                throw ex;
            }
        }
Exemple #3
0
        private bool GetThumbnailHelper(string file, IntPtr pidl, IShellFolder item)
        {
            IntPtr bitmapPointer = IntPtr.Zero;

            IExtractImage extractImage = null;

            try
            {
                string pidlPath = this.PathFromPidl(pidl);

                if (Path.GetFileName(pidlPath).ToUpper().Equals(Path.GetFileName(file).ToUpper()))
                {
                    IUnknown iunk            = null;
                    int      prgf            = 0;
                    Guid     iidExtractImage = new Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1");
                    item.GetUIObjectOf(IntPtr.Zero, 1, ref pidl, ref iidExtractImage, ref prgf, ref iunk);
                    extractImage = (IExtractImage)iunk;
                    if (extractImage != null)
                    {
                        Console.WriteLine("Got an IExtractImage object - " + file);
                        SIZE sz = new SIZE();
                        sz.HorizontalSize = this.DesiredSize.Width;
                        sz.VerticalSize   = this.DesiredSize.Height;
                        StringBuilder location             = new StringBuilder(260, 260);
                        int           priority             = 0;
                        int           requestedColourDepth = 32;
                        EIEIFLAG      flags     = EIEIFLAG.IEIFLAG_ASPECT | EIEIFLAG.IEIFLAG_SCREEN;
                        int           nameFlags = (int)flags;
                        extractImage.GetLocation(location, location.Capacity, ref priority, ref sz, requestedColourDepth, ref nameFlags);
                        extractImage.Extract(ref bitmapPointer);

                        if (bitmapPointer != IntPtr.Zero)
                        {
                            this.thumbNail = Bitmap.FromHbitmap(bitmapPointer);
                        }

                        Marshal.ReleaseComObject(extractImage);

                        extractImage = null;
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                if (bitmapPointer != IntPtr.Zero)
                {
                    UnmanagedMethods.DeleteObject(bitmapPointer);
                }

                if (extractImage != null)
                {
                    Marshal.ReleaseComObject(extractImage);
                }

                throw ex;
            }
        }
Exemple #4
0
        private bool getThumbNail(string file, IntPtr pidl, IShellFolder item)
        {
            IntPtr        hBmp         = IntPtr.Zero;
            IExtractImage extractImage = null;

            try
            {
                var pidlPath = pathFromPidl(pidl);
                if (!Path.GetFileName(pidlPath).ToUpper().Equals(Path.GetFileName(file).ToUpper()))
                {
                    return(false);
                }

                IUnknown iunk            = null;
                var      prgf            = 0;
                var      iidExtractImage = new Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1");
                item.GetUIObjectOf(IntPtr.Zero, 1, ref pidl, ref iidExtractImage, ref prgf, ref iunk);
                extractImage = (IExtractImage)iunk;
                if (extractImage == null)
                {
                    return(true);
                }

                var sz = new Size {
                    cx = DesiredSize.Width, cy = DesiredSize.Height
                };
                var            location             = new StringBuilder(260, 260);
                var            priority             = 0;
                const int      requestedColourDepth = 32;
                const EIEIFLAG flags =
                    EIEIFLAG.IeiflagScreen | EIEIFLAG.IeiflagAsync | EIEIFLAG.IeiflagQuality | EIEIFLAG.IeiflagCache;
                var uFlags = (int)flags;
                try
                {
                    extractImage.GetLocation(
                        location, location.Capacity, ref priority, ref sz, requestedColourDepth, ref uFlags);
                }
                catch { }

                extractImage.Extract(ref hBmp);

                if (hBmp != IntPtr.Zero)
                {
                    ThumbNail = Image.FromHbitmap(hBmp);
                }

                Marshal.ReleaseComObject(extractImage);
                extractImage = null;
                return(true);
            }
            finally
            {
                if (hBmp != IntPtr.Zero)
                {
                    UnmanagedMethods.DeleteObject(hBmp);
                }
                if (extractImage != null)
                {
                    Marshal.ReleaseComObject(extractImage);
                }
            }
        }