Example #1
0
        private static IntPtr GetIconHandleFromFilePath(string filepath, IconSizeEnum iconsize)
        {
            var        shinfo                = new Shell.SHFILEINFO();
            const uint SHGFI_SYSICONINDEX    = 0x4000;
            const int  FILE_ATTRIBUTE_NORMAL = 0x80;
            uint       flags = SHGFI_SYSICONINDEX;

            return(getIconHandleFromFilePathWithFlags(filepath, iconsize, ref shinfo, FILE_ATTRIBUTE_NORMAL, flags));
        }
Example #2
0
        private static IntPtr getIconHandleFromFilePathWithFlags(
            string filepath, IconSizeEnum iconsize,
            ref Shell.SHFILEINFO shinfo, int fileAttributeFlag, uint flags)
        {
            const int ILD_TRANSPARENT = 1;
            var       retval          = SHGetFileInfo(filepath, fileAttributeFlag, ref shinfo, Marshal.SizeOf(shinfo), flags);

            if (retval == 0)
            {
                throw (new System.IO.FileNotFoundException());
            }
            var iconIndex      = shinfo.iIcon;
            var iImageListGuid = new Guid("46EB5926-582E-4017-9FDF-E8998DAA0950");

            Shell.IImageList iml;
            var hres  = SHGetImageList((int)iconsize, ref iImageListGuid, out iml);
            var hIcon = IntPtr.Zero;

            hres = iml.GetIcon(iconIndex, ILD_TRANSPARENT, ref hIcon);
            return(hIcon);
        }
Example #3
0
 public static extern int SHGetFileInfo(
     string pszPath,
     int dwFileAttributes,
     ref Shell.SHFILEINFO psfi,
     int cbFileInfo,
     uint uFlags);