コード例 #1
0
 /// <summary>
 /// Get icon for executable
 /// </summary>
 /// <param name="path">path to the exe or dll</param>
 /// <param name="index">index of the icon</param>
 /// <returns>Bitmap with the icon or null if something happended</returns>
 private static Bitmap GetExeIcon(string path, int index)
 {
     if (!File.Exists(path))
     {
         return(null);
     }
     try
     {
         using (Icon appIcon = ImageHelper.ExtractAssociatedIcon(path, index, conf.UseLargeIcons))
         {
             if (appIcon != null)
             {
                 return(appIcon.ToBitmap());
             }
         }
         using (Icon appIcon = Shell32.GetFileIcon(path, conf.UseLargeIcons ? Shell32.IconSize.Large : Shell32.IconSize.Small, false))
         {
             if (appIcon != null)
             {
                 return(appIcon.ToBitmap());
             }
         }
     }
     catch (Exception exIcon)
     {
         LOG.Error("error retrieving icon: ", exIcon);
     }
     return(null);
 }
コード例 #2
0
        public void GetFileIcon()
        {
            Console.WriteLine("Filesystem.Shell32.GetFileIcon()");

            Console.WriteLine("\nInput File Path: [{0}]\n", NotepadExe);

            Console.WriteLine("Example usage:");
            Console.WriteLine("\n\tIntPtr icon = Shell32.GetFileIcon(file, FileAttributes.SmallIcon | FileAttributes.AddOverlays);");


            IntPtr icon = Shell32.GetFileIcon(NotepadExe, Shell32.FileAttributes.SmallIcon | Shell32.FileAttributes.AddOverlays);

            Console.WriteLine("\n\tIcon Handle: [{0}]", icon);

            Assert.IsTrue(icon != IntPtr.Zero, "Failed retrieving icon for: [{0}]", NotepadExe);
        }