Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for shell32iconsform.cs

(view source code of shell32iconsform.cs as plain text)

  1. using System;
  2. using System.Drawing;
  3. using System.Runtime.InteropServices;
  4. using System.Windows.Forms;
  5.  
  6.  
  7. namespace RobvanderWoude
  8. {
  9. 	public partial class Shell32IconsForm : Form
  10. 	{
  11. 		public static string progver = "1.00";
  12. 		public static int icon = 1;
  13.  
  14.  
  15. 		public Shell32IconsForm( )
  16. 		{
  17. 			InitializeComponent( );
  18. 			string[] args = Environment.GetCommandLineArgs( );
  19. 			if ( args.Length > 1 )
  20. 			{
  21. 				ShowHelp( );
  22. 			}
  23. 		}
  24.  
  25.  
  26. 		// Code to extract icons from Shell32.dll by Thomas Levesque
  27. 		// http://stackoverflow.com/questions/6873026
  28. 		public class IconExtractor
  29. 		{
  30.  
  31. 			public static Icon Extract( string file, int number, bool largeIcon )
  32. 			{
  33. 				IntPtr large;
  34. 				IntPtr small;
  35. 				ExtractIconEx( file, number, out large, out small, 1 );
  36. 				try
  37. 				{
  38. 					return Icon.FromHandle( largeIcon ? large : small );
  39. 				}
  40. 				catch
  41. 				{
  42. 					return null;
  43. 				}
  44.  
  45. 			}
  46.  
  47. 			[DllImport( "Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall )]
  48. 			private static extern int ExtractIconEx( string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons );
  49. 		}
  50.  
  51.  
  52. 		static void ShowHelp( )
  53. 		{
  54. 			string title = String.Format( "Shell32Icons {0} \xA9 2016 Rob van der Woude", progver );
  55. 			string helptext = String.Format( "Shell32Icons,  Version {0}\nView all icons available in Shell32.dll\n\n", progver );
  56. 			helptext += "Code to extract icons from Shell32.dll by Thomas Levesque:\nhttp://stackoverflow.com/questions/6873026\n\n";
  57. 			helptext += "Written by Rob van der Woude\nhttp://www.robvanderwoude.com";
  58. 			MessageBox.Show( helptext, title, MessageBoxButtons.OK, MessageBoxIcon.None );
  59. 		}
  60.  
  61.  
  62. 		private void numericUpDown_ValueChanged( object sender, EventArgs e )
  63. 		{
  64. 			icon = Convert.ToInt32( numericUpDown.Value );
  65. 			Shell32IconsForm.ActiveForm.Icon = IconExtractor.Extract( "shell32.dll", icon, true );
  66. 		}
  67.  
  68.  
  69. 		private void Shell32IconsForm_HelpRequested( object sender, HelpEventArgs hlpevent )
  70. 		{
  71. 			ShowHelp( );
  72. 		}
  73. 	}
  74. }
  75.  

page last uploaded: 2017-07-06, 12:37