No announcement yet.

File Explorer Icon Not Set

  • Filter
  • Time
  • Show
Clear All
new posts

  • File Explorer Icon Not Set

    The good thing about this code is that the EXE is not bloated by having a Resource icon. The Dialog and the TaskBar both show the chosen system icon.

    The bad thing about this code is that the EXE listing in File Explorer does not show the chosen system icon ("shield" in this case). Adding the icon via code is simple but I don't want the extra bytes.

    #Include ""
    Global hDlg,hIcon As Dword
    Function PBMain() As Long
       Dialog New Pixels, 0, "Email Date",300,300,350,200, %WS_OverlappedWindow To hDlg
       hIcon = LoadIcon(ByVal %Null, ByVal %IDI_Shield)  'use a system icon for the dialog
       SendMessage hDlg, %WM_SetIcon, %ICON_BIG, hIcon   'use a system icon for the dialog
       Dialog Show Modal hDlg
    End Function
    The extra bytes are not a big deal - I would just like to avoid it if possible.

  • #2
    Bloat is relative

    You'd trade showing the executable's icon for 1KB?

    Click image for larger version  Name:	ExeIcon.jpg Views:	3 Size:	7.4 KB ID:	805018


    • #3
      Howdy, Stuart!

      Yes, I would agree that practically speaking, the 1K bloat is unimportant. It's just the principle of it all. I would like to know if there's a way to use a system icon, without relying on #Resource code, so that the system icon will show up in File Explorer.

      In other situations, where I use #Resource Icon, I often use a 256x256 icon to support the DeskTop setting of Large Icons. That's a 65K bloat per icon and is really annoying.


      • #4
        Q: How can WIndows know what icon to use for a file if it's not in the file or associated with the file extension, but is only loaded from somewhere else at RUNTIME?
        A: It can't


        • #5
          Howdy, Stuart!

          My example was runtime code, but perhaps there is other code using API that can create a resource of a system icon at compile time, such that File Explorer can find it? Something that does Dialog Set Icon via API?


          • #6
            File management looks to the resource data within a file when it is initially saved.

            If a new file doesn't contain an icon, one is assigned, by extension association etc for display eg in a directory listing.

            All explorer file icons are actually saved to an icon cache database file and retrieved from there as needed (faster than interrogating the files each time).

            There doesn't seem to be any API for updating content of the icon cache. (If deleted the file system automatically regenerates it).

            Changing the resource content in memory is possible but updates are not recognised by the file system until written to storage.

            You could maybe save another executable of the same name that does have an icon then overwrite it with your real (icon less) file..

            That would cause the cache to deliver 'your' icon - at least until the next time the Icon Cache was refreshed
            Rgds, Dave