IconExtractor.cs
Description du code
IconExtractor.cs est un fichier du projet BrolDev.Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/broldev/src/.
Projet BrolDev : Librairie de composants réutilisables pour les applications BrolDev en CSharp.
Code source ou contenu du fichier
Code c# (IconExtractor.cs) (163 lignes)
using System; using System.Drawing; using System.IO; using System.Reflection; using System.Runtime.InteropServices; using be.gaudry.model.enums; namespace be.gaudry.model.drawing { /// <summary> /// Provides static methods to access Icons into executable files or dll. /// </summary> public class IconExtractor { #region declarations and constructor private static string shell32Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "shell32.dll"); private static IntPtr hInst; static IconExtractor() { hInst = Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]); } #endregion #region marshall shell32 dll [DllImport("shell32.dll", EntryPoint = "ExtractAssociatedIcon")] private static extern IntPtr ExtractAssociatedIcon( IntPtr hInst, [MarshalAs(UnmanagedType.LPStr)] string lpIconPath, ref int lpiIcon); [DllImport("shell32.dll", EntryPoint = "ExtractIcon")] private static extern IntPtr ExtractIcon( IntPtr hInst, [MarshalAs(UnmanagedType.LPStr)] string lpszExeFileName, int nIconIndex); #endregion #region public static methods /// <summary> /// Gets an Icon from the shell32.dll /// </summary> /// <param name="systemIcon">Icon identifier</param> /// <returns></returns> public static Icon getShell32Icon(SHELL32_ICON systemIcon) { try { return ExtractIcon(shell32Path, (int)systemIcon); } catch (Exception) { return null; } } /// <summary> /// Gets a Bitmap from the shell32.dll /// </summary> /// <param name="systemIcon">Icon identifier</param> /// <returns></returns> public static Bitmap getShell32Bitmap(SHELL32_ICON systemIcon) { try { return ExtractIcon(shell32Path, (int)systemIcon).ToBitmap(); } catch (Exception) { switch (systemIcon) { case SHELL32_ICON.goForwardSquare: return global::be.gaudry.Properties.Resources.wizard_big; } } } /// <summary> /// Gets the default Icon for an executable file or a dll /// </summary> /// <param name="fileName">Path of the executable file or a dll</param> /// <returns></returns> public static Icon ExtractAssociatedIcon(string fileName) { if (File.Exists(fileName) || Directory.Exists(fileName)) { int i = 0; IntPtr hIcon = ExtractAssociatedIcon(hInst, fileName, ref i); if (!hIcon.Equals(IntPtr.Zero)) { return Icon.FromHandle(hIcon); } else { return null; } } else { return null; } } /// <summary> /// Gets the first Icon of an executable file or a dll /// </summary> /// <param name="fileName">Path of the executable file or a dll</param> /// <returns></returns> public static Icon ExtractIcon(string fileName) { return ExtractIcon(fileName, 0); } /// <summary> /// Gets an Icon of an executable file or a dll /// </summary> /// <param name="fileName">Path of the executable file or a dll</param> /// <param name="index">position of the Icon in the Icons list in the file</param> /// <returns></returns> public static Icon ExtractIcon(string fileName, int index) { if (File.Exists(fileName) || Directory.Exists(fileName)) { System.IntPtr hIcon; hIcon = ExtractIcon(hInst, fileName, -1); if (hIcon.Equals(IntPtr.Zero)) { return ExtractAssociatedIcon(fileName); } else { int numOfIcons = hIcon.ToInt32(); if (0 <= index && index < numOfIcons) { hIcon = ExtractIcon(hInst, fileName, index); if (!hIcon.Equals(IntPtr.Zero)) { return Icon.FromHandle(hIcon); } else { return null; } } else { return null; } } } else { return null; } } #endregion } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1732276605 22/11/2024 12:56:45 |
| _ | colors | 0 octets | 1541007202 31/10/2018 18:33:22 |
| _ | chart | 0 octets | 1541007202 31/10/2018 18:33:22 |
Utilisation de l'explorateur de code
- Navigation :
- Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
- Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
- La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
- Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
- Affichage :
- Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
- Actions :
- Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 16/10/2009, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/cs-broldev-source-rf-model/drawing//IconExtractor.cs.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.