Set icon for Windows app

Started by
8 comments, last by songho 16 years ago
How can i set my application's .exe icon in Visual Studio using resource (.rc) files? I have looked on MSDN but only found how to actually load an icon using LoadIcon. Isn't there some setting in VS to specify the icon? thanks.
[Window Detective] - Windows UI spy utility for programmers
Advertisement
Here's a thread from a few months back with directions:

http://www.gamedev.net/community/forums/topic.asp?topic_id=469462
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.
If you simply want to set application icon, then you don't need a *.rc file. You just include an icon into your project and build (compile) it. That's it. The icon will be shown for the executable file.

If you include multiple icons, then the first added icon will become the application icon.
Ok, thanks. I thought it was something simple like that.
Mmm, i added my icon to the project (ProjectName -> Resource File -> Add -> Existing Item... then added my .ico file) but my exe doesn't have that icon. How do i get it to do that?
[Window Detective] - Windows UI spy utility for programmers
Is your icon file valid? Make sure it's not a .bmp file that was renamed to .ico... Those will work for shortcuts, but they won't work with exes or dlls. Use a "proper" icon editor instead.
Ha ha, no i'm pretty sure it's a proper .ico since i made it myself. Unless GIMP is the culprit (i made it in GIMP). It has a few bugs with .ico files but as far as i know they work with Windows. And it displays o.k. in explorer. It's 48x48 but that's ok right? I tried refreshing the view (F5) but that didn't work.
[Window Detective] - Windows UI spy utility for programmers
Wait, which icon works and which doesnt? Explorer shows the icon for your application but you also want it to be in the upper left corner of the app window as well as the icon next to the title in the app's Taskbar button, right?

To add an icon so that Explorer shows it you simply add an icon to the resource file. Explorer will pick the icon with the smallest resource ID to show.

To add an icon to the window itself you need to either set it as hIcon or hIconSm in the WNDCLASSEX structure or send the window WM_SETICON. This assumes you are using straight up Win32. If you want more specifics you'll need to explain what language and framework you are using.
When i said "And it displays o.k. in explorer", i meant the .ico file. The .exe still shows the default app icon.

EDIT: hey, guess what. I added the icon to the .rc file (100 ICON "Ballistic.ico") and it worked!
@songho: i guess i do need a .rc file. The strange thing is that i am not referring to it anywhere, i just id it by a number. VS must just pick the first icon i define as the application icon.

[Edited by - XTAL256 on April 3, 2008 4:03:22 AM]
[Window Detective] - Windows UI spy utility for programmers
I was under the impression that explorer takes the first icon resource it finds in the .exe.
I other words it uses the first icon found in the .rc (in reality it's probably the icon with the lowest resource id).

XTAL256,
Sorry for making you confused. You are right. You need a *.rc file for the application icon even if you don't reference it.

Apologies for false info.


This topic is closed to new replies.

Advertisement