Exemple #1
0
        public static IntPtr extractIcon(Object parentIShellFolder, IntPtr relativePIDL, Boolean getLargeIcon)
        {
            if (parentIShellFolder == null || relativePIDL == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }
            ShellApi.IShellFolder folder = (ShellApi.IShellFolder)parentIShellFolder;
            Guid   guid = new Guid("000214fa-0000-0000-c000-000000000046");
            object ppv;

            if (folder.GetUIObjectOf(IntPtr.Zero, 1, new IntPtr[] { relativePIDL }, ref guid, IntPtr.Zero, out ppv) == 0)
            {
                ShellApi.IExtractIcon extractor = (ShellApi.IExtractIcon)ppv;
                int           size = 1024;
                StringBuilder path = new StringBuilder(size);
                int           piIndex;
                uint          pwFlags;
                if (extractor.GetIconLocation((uint)ShellApi.GIL.GIL_FORSHELL, path, size, out piIndex, out pwFlags) == 0)
                {
                    IntPtr hIconL = new IntPtr();
                    IntPtr hIconS = new IntPtr();
                    if (extractor.Extract(path.ToString(), (uint)piIndex, out hIconL, out hIconS, (16 << 16) + 32) == 0)
                    {
                        if (getLargeIcon)
                        {
                            ShellApi.DestroyIcon(hIconS);
                            return(hIconL);
                        }
                        else
                        {
                            ShellApi.DestroyIcon(hIconL);
                            return(hIconS);
                        }
                    }
                }
            }
            return(IntPtr.Zero);
        }
Exemple #2
0
 public static void disposeIcon(IntPtr hIcon)
 {
     ShellApi.DestroyIcon(hIcon);
 }