[C++]Setting icon for an exe

Started by
4 comments, last by GameDev.net 12 years, 11 months ago
Hi,

I just wondered how to choose an icon for my compiled exe? I've got an application which I use normally use to replace icons, but these doesn't even work because my app hasn't even got a single icon. It's just that white box windows displays when somethings is wrong (missing files, etc..). How can I use an icon for my exe? I need it not to be updated at runtime, I just want to compile with icons. I'm using Visual C++ Studio 2010, regular c++ project (no form). Thanks!
Advertisement
Provided nothing has changed since I first learned about it (which was admittedly in the Win98 era), the icon used for the application is simply the icon with the lowest ID included in the executable's resource table.
Provided nothing has changed since I first learned about it (which was admittedly in the Win98 era), the icon used for the application is simply the icon with the lowest ID included in the executable's resource table. [/quote]

Seems quite simple, but how do I use resources anyway? Didn't use them till know, and I checked the internet, but couldn't find much useful information. I tried right-clicking on my project and move over add, but then all I can do is add a class as "resource" is greyed out. Any idea? I'm using visual c++ studio 2010 express, maybe express can't handle resources (which I don't really think)..?
Under 2008 its Project >> Add Existing Item (Or Project >> Add New Item >> Icon for new blank one)
Thanks, I tried it out. First I added the icon itself with Add Existing item and compiled. Didn't work. Then I noticed visual studio created a .rc file but didn't include in my project. I added it with Add Existing item, and studio told me that I can't edit resources with Visual studio express SKU. Seems that I need the professional edition to do so :/ Or is there any way around?

Seems quite simple, but how do I use resources anyway? Didn't use them till know, and I checked the internet, but couldn't find much useful information. I tried right-clicking on my project and move over add, but then all I can do is add a class as "resource" is greyed out. Any idea? I'm using visual c++ studio 2010 express, maybe express can't handle resources (which I don't really think)..?


Yep, doesn't work to add resources in the express version. You will get icons added to the project only if you create a win32 project. However you can add some files manually to have icons in your project:

resource.h

#define IDI_PROJECTNAME 107
#define IDI_SMALL 108


projectname.rc (this is the file responsible for creating your resource table, will be automatically compiled, you don't need to include it anywhere)

#include "windows.h"
#include "resource.h"

IDI_PROJECTNAME ICON "projectname.ico"
IDI_SMALL ICON "small.ico"


projectname.ico (size should be 48x48)
small.ico (size should be 16x16)

Just replace "projectname" with your own project name.

This topic is closed to new replies.

Advertisement