Ejemplo n.º 1
0
 public void Dispose()
 {
     this.icon = null;
     if (this.handle != null)
     {
         this.handle.Dispose();
         this.handle = null;
     }
 }
Ejemplo n.º 2
0
 private static IconContainer GetIconFromShell(string path, bool useExtension, bool largeIcon)
 {
     IconContainer container;
     ShellFileInfo structure = new ShellFileInfo();
     IconCriticalHandle critHandle = null;
     uint fileAttributes = 0x80;
     uint flags = 0x100;
     if (!largeIcon)
     {
         flags |= 1;
     }
     if (useExtension)
     {
         flags |= 0x10;
         if (string.IsNullOrEmpty(path))
         {
             fileAttributes = 0x10;
         }
     }
     try
     {
         int num3 = Marshal.SizeOf(structure);
         if (ShellAPI.SHGetFileInfo(path, fileAttributes, ref structure, (uint) num3, flags) == IntPtr.Zero)
         {
             throw new Win32Exception(Marshal.GetLastWin32Error());
         }
         if (structure.handle == IntPtr.Zero)
         {
             throw new Exception("You have exceeded the maximum number of open GDI handles. Close some of the existing icon handles to avoid this condition.");
         }
         critHandle = new IconCriticalHandle(structure.handle);
         container = new IconContainer(critHandle);
     }
     finally
     {
         if ((critHandle == null) && (structure.handle != IntPtr.Zero))
         {
             ShellAPI.DestroyIcon(structure.handle);
         }
     }
     return container;
 }
Ejemplo n.º 3
0
 public IconContainer(IconCriticalHandle critHandle)
 {
     this.handle = critHandle;
     this.icon = System.Drawing.Icon.FromHandle(critHandle.Handle);
 }