News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

how to get default icon for exe files

Started by Ar0n, August 23, 2015, 08:38:52 AM

Previous topic - Next topic

Ar0n

As the title says, how do I get the default icon for the exe files?
for example, the default icon in window XP is :
in Window 7:
is there some safe/correct way to get this icon?

I found an application that does what I want:
http://www.nirsoft.net/utils/file_types_manager.html

not sure how it gets the icons...
any idea?

jj2007

Use SHGetFileInfo with the name of an existing executable - e.g. your own application. If it doesn't have an icon (see LoadIcon with IDI_APPLICATION), you'll get exactly what you wanted.

dedndave

LoadIcon

https://msdn.microsoft.com/en-us/library/windows/desktop/ms648072%28v=vs.85%29.aspx

to load a system-defined icon (IDI_APPLICATION is the specific one you want)

    INVOKE  LoadIcon,0,IDI_APPLICATION

to load one from resource

    INVOKE  LoadIcon,hInstance,lpIconName

where lpIconName is either a resource ID number (less than 65536)
or, a pointer to a resource name string (rarely used this way)

in either case, EAX returns an HICON handle
if it is associated with a window, it will be deleted when the window is destroyed
otherwise, you should use DestroyIcon for non-system icon handles

Ar0n

Well, I wanted to get the default system icon of EXE files... not the current icon of my application :-P but SHGetFileInfo worked by passing the extension! thanks!  Added the project if it's useful for someone else.
I tested it on Windows XP and 7.

If anyone can try it in Windows Vista, 8 or 10, it would be great.

dedndave

    INVOKE  LoadIcon,NULL,IDI_APPLICATION
    mov     hIcon,eax


QuoteIDI_APPLICATION  Default application icon.

Ar0n

Quote from: dedndave on August 23, 2015, 12:27:45 PM
    INVOKE  LoadIcon,NULL,IDI_APPLICATION
    mov     hIcon,eax


QuoteIDI_APPLICATION  Default application icon.
:t that worked as well! I thought you meant the custom icon you can set in the application. thanks dave.

Now I'm trying to get x48 and/or higher dimensions :-P

dedndave

the dimension of an application icon will be fixed
you can get the size by calling GetSystemMetrics

QuoteSM_CXICON  The default width of an icon, in pixels. The LoadIcon function can load only icons with the dimensions that SM_CXICON and SM_CYICON specifies.

SM_CYICON  The default height of an icon, in pixels. The LoadIcon function can load only icons with the dimensions that SM_CXICON and SM_CYICON specifies.

of course, the operating system has that icon in a DLL, likely at various sizes
it's probably in Shell32.dll
however, you need the correct ordinal to index that icon
and - the ordinal may change from one windows version to the next (they usually don't)

to load icons of sizes other than those dimensioned by SM_CXICON and SM_CYICON,
you can use LoadImage

the best thing to do is to get the icon you want, in the sizes you want, and add them to the EXE as resource

dedndave


dedndave

from what i can see, that icon (shell32.dll, index #3, XP) only comes in 32x32 and 16x16

it's a boring icon - pick something better - lol