Esempio n. 1
0
 public IconLocation(string fileName, int index, GILI iconFlags, SHIL size)
 {
     FileName  = string.Intern(Path.GetFullPath(fileName));
     Index     = index;
     IconFlags = iconFlags;
     Size      = size;
 }
        public static IImageList SHGetImageList(SHIL iImageList)
        {
            object ppv;

            SHGetImageList(iImageList, typeof(IImageList).GUID, out ppv);
            return((IImageList)ppv);
        }
        public static ImageSource GetIcon(string path, SHIL size)
        {
            IntPtr     result     = IntPtr.Zero;
            SHFILEINFO shFileInfo = new SHFILEINFO();

            if (path.StartsWith(".") || path.StartsWith(@"\\"))
            {
                result = SHGetFileInfo(path, FileAttributes.Normal, ref shFileInfo, Marshal.SizeOf(shFileInfo), SHGFI.SHGFI_SYSICONINDEX | SHGFI.SHGFI_USEFILEATTRIBUTES);
            }
            else
            {
                PIDL pidl = ILCreateFromPath(path);
                result = SHGetFileInfo(pidl, FileAttributes.Normal, ref shFileInfo, Marshal.SizeOf(shFileInfo), SHGFI.SHGFI_SYSICONINDEX | SHGFI.SHGFI_PIDL);
            }

            if (result == IntPtr.Zero)
            {
                return(null);
            }

            SHGetImageList(size, ImageListId, out IImageList iImageList);
            SafeHICON hIcon = iImageList.GetIcon(shFileInfo.iIcon, IMAGELISTDRAWFLAGS.ILD_IMAGE);

            ImageSource imageSource = hIcon.ToBitmapSource();

            imageSource.Freeze();
            DestroyIcon(hIcon);

            return(imageSource);
        }
Esempio n. 4
0
        private ImageSource GetIcon(SHIL iconSize, GILI iconAttrs)
        {
            int iconIndex = GetIconIndex(iconAttrs);

            return(iconIndex != UnindexableIconIndex
                ? _tree.IconList.GetIconByIndex(iconSize, iconIndex)
                : _tree.IconList.ExtractIcon(ParentShellFolder, _pidl, iconSize, iconAttrs));
        }
Esempio n. 5
0
        public static IImageList SHGetImageList(SHIL iImageList)
        {
            var    iid = typeof(IImageList).GUID;
            object imageList;
            int    hr = SHGetImageList(iImageList, ref iid, out imageList);

            return(hr >= 0
                ? (IImageList)imageList
                : null);
        }
Esempio n. 6
0
        ///   <summary>
        ///    Associates a SysImageList with a ListView control
        ///    </summary>
        ///    <param name="listView">ListView control to associate ImageList with</param>
        ///    <param name="Usage">State, Group, Normal, Small
        ///                   false=Set Small Icon List</param>
        ///    <param name="IIlSize">Size of Images</param>
        public static void SetListViewImageList(ListView listView, LVSIL Usage, SHIL IIlSize)
        {
            Initializer();
            int    wParam     = (int)Usage;
            IntPtr HImageList = m_lgImgList;

            if (IIlSize == SHIL.Small)
            {
                HImageList = m_smImgList;
            }
            else if (IIlSize == SHIL.Jumbo)
            {
                HImageList = m_jumboImgList;
            }
            else if (IIlSize == SHIL.XLarge)
            {
                HImageList = m_xlgImgList;
            }

            User32.SendMessage(listView.Handle, MSG.LVM_SETIMAGELIST, wParam, HImageList);
        }
Esempio n. 7
0
        public static Bitmap GetJumboIcon(string filePath)
        {
            SHFILEINFO shinfo = new SHFILEINFO();
            IntPtr     hImg   = SHGetFileInfo(filePath, 0, out shinfo, (uint)Marshal.SizeOf(typeof(SHFILEINFO)), SHGFI.SHGFI_SYSICONINDEX);

            SHIL currentShil = SHIL.SHIL_JUMBO;

            IImageList imgList = null;

            int result = SHGetImageList(currentShil, ref IID_IImageList, out imgList);

            IntPtr hIcon = IntPtr.Zero;

            imgList.GetIcon(shinfo.iIcon, (int)ImageListDrawItemConstants.ILD_TRANSPARENT, ref hIcon);

            Icon icon = Icon.FromHandle(hIcon);

            Bitmap bmp = icon.ToBitmap();

            return(bmp);
            //bmp.Save("C:/Users/Christian/Desktop/img.png", System.Drawing.Imaging.ImageFormat.Png);
        }
Esempio n. 8
0
        private static int IconSizeToPixels(SHIL iconSize)
        {
            // TODO Properly calculate icon size using GetSystemMetrics
            switch (iconSize)
            {
            case SHIL.SMALL:
            case SHIL.SYSSMALL:
                return(16);

            case SHIL.LARGE:
                return(32);

            case SHIL.EXTRALARGE:
                return(48);

            case SHIL.JUMBO:
                return(256);

            default:
                throw new ArgumentOutOfRangeException("iconSize");
            }
        }
Esempio n. 9
0
 private static extern int SHGetImageList(SHIL iImageList, ref Guid iid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 1)] out object imageList);
Esempio n. 10
0
 public ImageSource GetIconByIndex(SHIL iconSize, int index)
 {
     return(index >= 0 ? GetImageList(iconSize).GetIconImageSource(index) : null);
 }
Esempio n. 11
0
 public static extern int SHGetImageList(SHIL iImageList, ref Guid riid, out IntPtr ppv);
Esempio n. 12
0
 public ImageSource ExtractIcon(NativeShellFolder shellFolder, PIDLIST pidl, SHIL iconSize, GILI iconFlags)
 {
     return(ExtractIcon(shellFolder, pidl, IconSizeToPixels(iconSize), iconFlags));
 }
Esempio n. 13
0
 private ShellImageList GetImageList(SHIL iconSize)
 {
     return(_imageLists.GetOrAdd(iconSize, () => new ShellImageList(iconSize)));
 }
Esempio n. 14
0
 public ShellImageList(SHIL iconSize)
 {
     _imageList        = new NativeImageList(Native.SHGetImageList(iconSize));
     _imageSourceCache = new IndexDictionary <ImageSource>();
 }
Esempio n. 15
0
 private static extern int SHGetImageList(SHIL iImageList, [MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv);
Esempio n. 16
0
 public ImageSource GetIcon(NativeShellIcon shellIcon, PIDLIST pidl, SHIL iconSize, GILI iconFlags)
 {
     return(GetIconByIndex(iconSize, GetIconIndex(shellIcon, pidl, iconFlags)));
 }
Esempio n. 17
0
 public ImageSource GetIconOverlay(NativeShellIconOverlay shellIconOverlay, PIDLIST pidl, SHIL iconSize)
 {
     return(GetIconByIndex(iconSize, GetIconOverlayIndex(shellIconOverlay, pidl)));
 }
Esempio n. 18
0
 public extern static int SHGetImageList(SHIL iImageList, ref Guid riid, out IImageList ppv);
Esempio n. 19
0
 private ImageSource GetIconOverlay(SHIL iconSize)
 {
     return(_tree.IconList.GetIconByIndex(iconSize, GetIconOverlayIndex()));
 }