Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Shell icons

Shell icons

Scheduled Pinned Locked Moved C#
csharplinuxtutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PaulPrice
    wrote on last edited by
    #1

    Dear all, If for example I am trying to make a custom folder explorer (to display PSP film names correctly) and I am using a TreeView to display the folder hierachy. Is it possible to access the system icons for example the currently used Folder icon from the Shell to use?? Many thanks Paul ps VS2005 and C#

    S 1 Reply Last reply
    0
    • P PaulPrice

      Dear all, If for example I am trying to make a custom folder explorer (to display PSP film names correctly) and I am using a TreeView to display the folder hierachy. Is it possible to access the system icons for example the currently used Folder icon from the Shell to use?? Many thanks Paul ps VS2005 and C#

      S Offline
      S Offline
      Saqib Mehmood
      wrote on last edited by
      #2

      for getting file icons you need to use shell APIs. you can use the following snippet.

      // define a struct for getting info from shell

      [StructLayout(LayoutKind.Sequential)]
      public struct SHFILEINFO
      {
      public IntPtr hIcon;
      public IntPtr iIcon;
      public uint dwAttributes;
      [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
      public string szDisplayName;
      [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
      public string szTypeName;
      };

      // define this class for invoking shell api to get file information
      class Win32
      {
      public const uint SHGFI_ICON = 0x100;
      public const uint SHGFI_LARGEICON = 0x0; // 'Large icon
      public const uint SHGFI_SMALLICON = 0x1; // 'Small icon

      \[DllImport("shell32.dll")\]
      public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
      

      }

      // write the following code where you want to get the selected file icon.

      IntPtr hImgSmall; //the handle to the system image list
      string fName = "c:\\getfileicon.cs"; // 'the file name to get icon from
      SHFILEINFO shinfo = new SHFILEINFO();

      //Use this to get the small Icon
      hImgSmall = Win32.SHGetFileInfo(fName, 0, ref shinfo,(uint)Marshal.SizeOf(shinfo),Win32.SHGFI_ICON |Win32.SHGFI_SMALLICON);

      /*
      //Use this to get the small Icon
      hImgLarge = Win32.SHGetFileInfo(fName, 0, ref shinfo,(uint)Marshal.SizeOf(shinfo),Win32.SHGFI_ICON |Win32.SHGFI_LARGEICON);
      */

      //The icon is returned in the hIcon member of the shinfo struct
      System.Drawing.Icon myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon);

      // do whatever with this icon. i.e I am adding it to an Image List.
      imageList1.Images.Add(myIcon);

      I think this code would be helpful.

      Saqib

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups