News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

What icon is used as displayed in explorer

Started by Magnum, February 03, 2013, 12:29:49 PM

Previous topic - Next topic

Magnum

I am looking for info on how to determine what icon a program uses that is displayed in explorer.


for ex. Hunter_Borg.exe creates it's log files named Shield.azx in various directories.
           
So all .azx files uses one of the icon resources. That are multiple icons of the same image in varying resolutions.

I would like to put more than one icon resource in my program, but don't know the process used to determine which icon is used.

Do you determine the screen resolution that is supported first ?

Thanks.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

it depends a little bit on which version of windows you are using

i generally put one in there that is 16x16 for detail view and one that is 32x32 for the other views
i think XP will use one that is up to 48x48 for certain viewing modes - and supports 4 or 8 bpp
newer os's will use larger icons, up to 256x256, i think, and also support 24 and 32 bpp

but - if windows doesn't find the size that it wants for a particular viewing mode, it will resize the one you have

mywan

There is a couple of different ways explorer sets the display icon. For executables the icon is a resource in the executable itself and displays the icon with index 0. For other file types the icon resource is defined in the registry. Under HKEY_CLASSES_ROOT the entries starting with a period '.' are file types. The default registry entry, such as HKEY_CLASSES_ROOT\.7z, will have string data such as 'IZArc7Z'. IZArc7Z is then the effective file type for windows. Then, to see the icon associated with *.7z you go to HKEY_CLASSES_ROOT\IZArc7Z\DefaultIcon. The default entry with be a path such as C:\Program Files\IZArc\Icons\7Z.ico.

The above icon path is a simple path icon. There is also a method of addressing specific icons embedded inside executables and other files containing icon resources. Take a batfile for instance. *.bat. The icon resource is located at HKEY_CLASSES_ROOT\batfile\DefaultIcon in the registry, with a default icon path that looks like %SystemRoot%\System32\imageres.dll,-68. Here imageres.dll is the file containing the icon resources and the -68 is the index of the particular icon you want to select from possibly multiple icons in the .dll resource. The same addressing scheme works to use selected icons from inside an exe, etc.

You do not need to determine the screen resolution first. If you want different icons displayed depending on screen resolution simply select an *.ico containing multiple resolutions. These will appear as a single ico file. Even single icons referenced by an index inside a resource file may contain multiple resolutions. The closest fit to a given resolution will get used and resized accordingly.

You can download various freeware icon explorers/viewers to view and save icons contained in various file formats. I like Resource Hacker for one.

There a several window APIs for handling icon related functions if you want to go that route.

Magnum

Thanks for the icon information.

It will provide useful tips that I will use.

One particular program contains 168 icons with the same image.

It seemed like an awful lot.

Andy

I am trying figure out whats wrong with setting the default program for different file types.

The file association works with the correct program but the icon displayed in explorer is not the one that the program uses.

I have experimented with several file types and freeware programs, so it doesn't sound like an issue with just one "rogue" program. :-)



Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

the icon displayed for an EXE is different than one displayed for other file types
two different subjects, actually

global file associations are stored in HKEY_LOCAL_MACHINE\Software\Classes
user-specific associations are stored in HKEY_CURRENT_USER\Software\Classes

when you log in, windows takes the ones from HKLM and overlays the ones from HKCU on top of it
(that is a somewhat simplified description, as there are also user profiles and WOW's)
this "virtualized" version of classes creates the HKEY_CLASSES_ROOT hive
when you make changes in HKCR, they are actually written to HKLM
i prefer to make changes in HKLM, as things can get messed up if you edit HKCR directly

so - to view it, look at HKCR
to edit it, use HKLM or HKCU, as appropriate
and - you may have to log out and in again (or reboot) to have changes take affect

after that, mywan's description is pretty good

if you look at the associations for one you are familiar with, it helps to understand
let's use .TXT
so, in RegEdit, go to HKCR\.txt
under that key, you will see the "default" value of "txtfile"
i think this is called a Programmatic Identifier - something like that

next, you can view the associations for that progID in HKCR\txtfile
under that key, you will find a subkey for the default icon
and another subkey for the shell
the shell entries control what happens when you click on the file to open
it also controls the list of available commands when you right-click on a file of that type

Magnum

Quote from: dedndave on February 03, 2013, 11:58:51 PM
t

global file associations are stored in HKEY_LOCAL_MACHINE\Software\Classes
user-specific associations are stored in HKEY_CURRENT_USER\Software\Classes

when you log in, windows takes the ones from HKLM and overlays the ones from HKCU on top of it
(that is a somewhat simplified description, as there are also user profiles and WOW's)
this "virtualized" version of classes creates the HKEY_CLASSES_ROOT hive
when you make changes in HKCR, they are actually written to HKLM
i prefer to make changes in HKLM, as things can get messed up if you edit HKCR directly

so - to view it, look at HKCR
to edit it, use HKLM or HKCU, as appropriate
and - you may have to log out and in again (or reboot) to have changes take affect

after that, mywan's description is pretty good

if you look at the associations for one you are familiar with, it helps to understand
let's use .TXT
so, in RegEdit, go to HKCR\.txt
under that key, you will see the "default" value of "txtfile"
i think this is called a Programmatic Identifier - something like that

next, you can view the associations for that progID in HKCR\txtfile
under that key, you will find a subkey for the default icon
and another subkey for the shell
the shell entries control what happens when you click on the file to open
it also controls the list of available commands when you right-click on a file of that type

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.txt]
@="txtfile"
"PerceivedType"="text"
"Content Type"="text/plain"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.txt\PersistentHandler]
@="{5e941d80-bf96-11cd-b579-08002b30bfeb}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.txt\ShellNew-]
"NullFile"=""


Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.txt]
@="txtfile"
"PerceivedType"="text"
"Content Type"="text/plain"

[HKEY_CLASSES_ROOT\.txt\PersistentHandler]
@="{5e941d80-bf96-11cd-b579-08002b30bfeb}"

[HKEY_CLASSES_ROOT\.txt\ShellNew-]
"NullFile"=""
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

[HKEY_CLASSES_ROOT\.txt]
@="txtfile"


now, export the ones from [HKEY_CLASSES_ROOT\txtfile]

Magnum

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

check again

[HKEY_CLASSES_ROOT\txtfile]
@="Text Document"
"FriendlyTypeName"=hex(2):40,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,\
  00,6f,00,6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,\
  32,00,5c,00,6e,00,6f,00,74,00,65,00,70,00,61,00,64,00,2e,00,65,00,78,00,65,\
  00,2c,00,2d,00,34,00,36,00,39,00,00,00
"EditFlags"=dword:00010000
"BrowserFlags"=dword:00000008

[HKEY_CLASSES_ROOT\txtfile\DefaultIcon]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,73,00,68,00,\
  65,00,6c,00,6c,00,33,00,32,00,2e,00,64,00,6c,00,6c,00,2c,00,2d,00,31,00,35,\
  00,32,00,00,00

[HKEY_CLASSES_ROOT\txtfile\shell]
@="open"

[HKEY_CLASSES_ROOT\txtfile\shell\open]

[HKEY_CLASSES_ROOT\txtfile\shell\open\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,4f,00,\
  54,00,45,00,50,00,41,00,44,00,2e,00,45,00,58,00,45,00,20,00,25,00,31,00,00,\
  00

[HKEY_CLASSES_ROOT\txtfile\shell\print]

[HKEY_CLASSES_ROOT\txtfile\shell\print\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,4f,00,\
  54,00,45,00,50,00,41,00,44,00,2e,00,45,00,58,00,45,00,20,00,2f,00,70,00,20,\
  00,25,00,31,00,00,00

[HKEY_CLASSES_ROOT\txtfile\shell\printto]

[HKEY_CLASSES_ROOT\txtfile\shell\printto\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,6e,00,6f,00,\
  74,00,65,00,70,00,61,00,64,00,2e,00,65,00,78,00,65,00,20,00,2f,00,70,00,74,\
  00,20,00,22,00,25,00,31,00,22,00,20,00,22,00,25,00,32,00,22,00,20,00,22,00,\
  25,00,33,00,22,00,20,00,22,00,25,00,34,00,22,00,00,00

dedndave

if i translate that unicode string to ansi, my default icon for txtfile's is
%SystemRoot%\system32\shell32.dll,-152

dedndave

you can create a file from the command line...
reg export hkcr\txtfile temp.txt
that way, you don't have to leaf through regedit to find it
and it's safe because it won't accidently make any changes (other than overwriting a temp.txt file)

Tedd

For non-exe file types, the registry is checked for an entry specifying the correct icon, otherwise a default is used.

For exe files, the exe's resources are checked and the first icon resource found is used (which may contain multiple icons in different sizes and colour formats - the best match for the current screen mode and icon size is used), otherwise the default exe icon is used.


For building your program, add the 'program icon' as the first icon resource, with any other icons after as separate icon resources. Minimally, your program icon should have 48x48 (tile view), 32x32 (icon view), and 16x16 (list view) sizes - the colour format isn't so important these days; I usually use 256 colours for the large icons and 16 for the smaller one.
If you're aiming for Vista+ then sizes can be up to 256x256, but have a different format (PNG).
Potato2