Geen cache-versie.

Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

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

  1. using System;
  2. using System.Drawing;
  3. using System.IO;
  4. using System.Reflection;
  5. using System.Runtime.InteropServices;
  6. using be.gaudry.model.enums;
  7.  
  8. namespace be.gaudry.model.drawing
  9. {
  10. /// <summary>
  11. /// Provides static methods to access Icons into executable files or dll.
  12. /// </summary>
  13. public class IconExtractor
  14. {
  15. #region declarations and constructor
  16.  
  17. private static string shell32Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "shell32.dll");
  18. private static IntPtr hInst;
  19.  
  20. static IconExtractor()
  21. {
  22. hInst = Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]);
  23. }
  24.  
  25. #endregion
  26.  
  27. #region marshall shell32 dll
  28. [DllImport("shell32.dll", EntryPoint = "ExtractAssociatedIcon")]
  29. private static extern IntPtr ExtractAssociatedIcon(
  30. IntPtr hInst,
  31. [MarshalAs(UnmanagedType.LPStr)] string lpIconPath,
  32. ref int lpiIcon);
  33.  
  34. [DllImport("shell32.dll", EntryPoint = "ExtractIcon")]
  35. private static extern IntPtr ExtractIcon(
  36. IntPtr hInst,
  37. [MarshalAs(UnmanagedType.LPStr)] string lpszExeFileName,
  38. int nIconIndex);
  39. #endregion
  40.  
  41. #region public static methods
  42. /// <summary>
  43. /// Gets an Icon from the shell32.dll
  44. /// </summary>
  45. /// <param name="systemIcon">Icon identifier</param>
  46. /// <returns></returns>
  47. public static Icon getShell32Icon(SHELL32_ICON systemIcon)
  48. {
  49. try
  50. {
  51. return ExtractIcon(shell32Path, (int)systemIcon);
  52. }
  53. catch (Exception)
  54. {
  55. return null;
  56. }
  57. }
  58. /// <summary>
  59. /// Gets a Bitmap from the shell32.dll
  60. /// </summary>
  61. /// <param name="systemIcon">Icon identifier</param>
  62. /// <returns></returns>
  63. public static Bitmap getShell32Bitmap(SHELL32_ICON systemIcon)
  64. {
  65. try
  66. {
  67. return ExtractIcon(shell32Path, (int)systemIcon).ToBitmap();
  68. }
  69. catch (Exception)
  70. {
  71. switch (systemIcon)
  72. {
  73. case SHELL32_ICON.goForwardSquare:
  74. return global::be.gaudry.Properties.Resources.wizard_big;
  75. }
  76. return new Bitmap(1, 1);
  77. }
  78. }
  79. /// <summary>
  80. /// Gets the default Icon for an executable file or a dll
  81. /// </summary>
  82. /// <param name="fileName">Path of the executable file or a dll</param>
  83. /// <returns></returns>
  84. public static Icon ExtractAssociatedIcon(string fileName)
  85. {
  86. if (File.Exists(fileName) || Directory.Exists(fileName))
  87. {
  88. int i = 0;
  89.  
  90. IntPtr hIcon = ExtractAssociatedIcon(hInst, fileName, ref i);
  91.  
  92. if (!hIcon.Equals(IntPtr.Zero))
  93. {
  94. return Icon.FromHandle(hIcon);
  95. }
  96. else
  97. {
  98. return null;
  99. }
  100. }
  101. else
  102. {
  103. return null;
  104. }
  105. }
  106. /// <summary>
  107. /// Gets the first Icon of an executable file or a dll
  108. /// </summary>
  109. /// <param name="fileName">Path of the executable file or a dll</param>
  110. /// <returns></returns>
  111. public static Icon ExtractIcon(string fileName)
  112. {
  113. return ExtractIcon(fileName, 0);
  114. }
  115. /// <summary>
  116. /// Gets an Icon of an executable file or a dll
  117. /// </summary>
  118. /// <param name="fileName">Path of the executable file or a dll</param>
  119. /// <param name="index">position of the Icon in the Icons list in the file</param>
  120. /// <returns></returns>
  121. public static Icon ExtractIcon(string fileName, int index)
  122. {
  123. if (File.Exists(fileName) || Directory.Exists(fileName))
  124. {
  125. System.IntPtr hIcon;
  126.  
  127. hIcon = ExtractIcon(hInst, fileName, -1);
  128.  
  129. if (hIcon.Equals(IntPtr.Zero))
  130. {
  131. return ExtractAssociatedIcon(fileName);
  132. }
  133. else
  134. {
  135. int numOfIcons = hIcon.ToInt32();
  136.  
  137. if (0 <= index && index < numOfIcons)
  138. {
  139. hIcon = ExtractIcon(hInst, fileName, index);
  140.  
  141. if (!hIcon.Equals(IntPtr.Zero))
  142. {
  143. return Icon.FromHandle(hIcon);
  144. }
  145. else
  146. {
  147. return null;
  148. }
  149. }
  150. else
  151. {
  152. return null;
  153. }
  154. }
  155. }
  156. else
  157. {
  158. return null;
  159. }
  160. }
  161. #endregion
  162. }
  163. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/model/drawing/ 
IcôneNomTailleModification
IcôneNomTailleModification
| _ Répertoire parent0 octets1714399406 29/04/2024 16:03:26
| _colors0 octets1541007202 31/10/2018 18:33:22
| _chart0 octets1541007202 31/10/2018 18:33:22
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/model/drawing/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csIconExtractor.cs5.18 Ko31/10/2018 18:33:08-refusé-
Afficher le fichier .cs|.csImageHelper.cs7.19 Ko31/10/2018 18:33:08-refusé-
Afficher le fichier .cs|.csBrolImage.cs6.29 Ko31/10/2018 18:33:08-refusé-
Afficher le fichier .cs|.csDibToImage.cs8.83 Ko31/10/2018 18:33:08-refusé-

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.

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 16/10/2009 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/cs-broldev-source-rf-model/drawing/IconExtractor.cs.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.