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. Retrieving correct indexed icon from iconfiles / exefiles

Retrieving correct indexed icon from iconfiles / exefiles

Scheduled Pinned Locked Moved C#
databasewindows-adminbeta-testinghelpquestion
2 Posts 1 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.
  • L Offline
    L Offline
    Larantz
    wrote on last edited by
    #1

    Hi everyone. Still working on my CustomGridColumnStyle class. So far I'm traversing the registry correctly, and I retrieve the correct exe-file or dll-file that contains icons for a specific filetype. Only problem is that for instance the icons for .txt files is located in shell32.dll at index -152, or atleast I believe it's index -152 due to registryvalue: "%SystemRoot%\system32\shell32.dll,-152" in subkey: "DefaultIcon", and I'm not pointing to that index so I just get the icon for dll-files when I display the txt-files... For extracting the icon I use Win32.SHGetFileInfo(..), and I'm wondering: Is there any way of specifying which icon you want extraced? By index perhaps?

    hImgSmall = Win32.SHGetFileInfo(filePath, 0, ref shinfo,
    (uint)Marshal.SizeOf(shinfo),
    Win32.SHGFI_ICON |
    Win32.SHGFI_SMALLICON);

    I think the Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON points to some kind of index though. If anyone has any knowledge of Win32.SHGetFileInfo I'd really appreciate some feedback. -Larantz-

    L 1 Reply Last reply
    0
    • L Larantz

      Hi everyone. Still working on my CustomGridColumnStyle class. So far I'm traversing the registry correctly, and I retrieve the correct exe-file or dll-file that contains icons for a specific filetype. Only problem is that for instance the icons for .txt files is located in shell32.dll at index -152, or atleast I believe it's index -152 due to registryvalue: "%SystemRoot%\system32\shell32.dll,-152" in subkey: "DefaultIcon", and I'm not pointing to that index so I just get the icon for dll-files when I display the txt-files... For extracting the icon I use Win32.SHGetFileInfo(..), and I'm wondering: Is there any way of specifying which icon you want extraced? By index perhaps?

      hImgSmall = Win32.SHGetFileInfo(filePath, 0, ref shinfo,
      (uint)Marshal.SizeOf(shinfo),
      Win32.SHGFI_ICON |
      Win32.SHGFI_SMALLICON);

      I think the Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON points to some kind of index though. If anyone has any knowledge of Win32.SHGetFileInfo I'd really appreciate some feedback. -Larantz-

      L Offline
      L Offline
      Larantz
      wrote on last edited by
      #2

      Found another solution, though I'm still interested in an answer on the above question. The other solution is to pass other constants to the SHGetFileInfo(..) method so that the method retrieves icons corresponding to fileextension, and not from the file itself. I'll just post it incase someone else is having the same problems: In Win32

      public const uint SHGFI_ICON = 0x100;
      public const uint SHGFI_LARGEICON = 0x0; // 'Large icon
      public const uint SHGFI_SMALLICON = 0x1; // 'Small icon
      public const uint SHGFI_USEFILEATTRIBUTES = 0x10;
      public const uint FILE_ATTRIBUTE_NORMAL = 0x80;
      public const uint SHGFI_TYPENAME = 0x400;

      In myClass

      hImgSmall = Win32.SHGetFileInfo(
      strAnyfilename, //this can even be a string to a nonexiting file
      Win32.FILE_ATTRIBUTE_NORMAL,
      ref shinfo,
      (uint)Marshal.SizeOf(shinfo),
      Win32.SHGFI_USEFILEATTRIBUTES |
      Win32.SHGFI_TYPENAME |
      Win32.SHGFI_ICON |
      Win32.SHGFI_SMALLICON);

      -Larantz- -- modified at 6:55 Wednesday 31st May, 2006

      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