Embed and set main icon using VC++

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
Jive Dadson
Experienced Solver
Experienced Solver
Posts: 60
Joined: Thu Sep 06, 2012 8:00 pm

Embed and set main icon using VC++

Post by Jive Dadson »

I have an icon file, say foo.ico

I want to embed it as a resource and make it the main icon so that Windows Explorer and the task bar can find it.

What are the steps? I am befuddled.
Jive Dadson
Experienced Solver
Experienced Solver
Posts: 60
Joined: Thu Sep 06, 2012 8:00 pm

Re: Embed and set main icon using VC++

Post by Jive Dadson »

I found the following on the www. I tried following the instructions, but rather than getting a new resource with the foo.icon in it,
my resources wind up containing the new resource file without the icon in it, and foo.ico as another resource.

The way Windows chooses the icon of the main executable file is that it looks for the first icon in the resource section of the executable, or something along these lines. First of all, you need to add a resource script, .rc file. This is done through Project->Add New Item or right click on solution explorer and go to Add->New Item. Chose Resource->Resrouce File(.rc) name it then add it.

Now you have the resource file then you add the icon to it. Go to resource view and right click on the name of your resource file. Right at the bottom you will find Add Resource, select that then a new window will pop up.

If you already have your icon saved seperatly then you should choose Import and then import the icon. Otherwise select Icon and then press New. The icon will be created and/or added to the resource script and you will find that when you build your project it will be the icon for the executable file.
Jive Dadson
Experienced Solver
Experienced Solver
Posts: 60
Joined: Thu Sep 06, 2012 8:00 pm

Re: Embed and set main icon using VC++

Post by Jive Dadson »

I managed to do it, but there must be a better way.

I copied a resource file, namely sample.rc, from the wxWidgets samples. I edited it in a text editor, replacing the icon name with foo.ico in a couple of places. I also commented-out an #include that referred to a wxWidget project directory. In Visual Studio, I added that file to the resources. In the MyFrame constructor in my program, I wrote,

Code: Select all

SetIcon(wxICON(sample));
Very hackish, but it worked.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: Embed and set main icon using VC++

Post by PB »

I do not think there is anything hackish on the procedure you described, this is how it is done if you do not have a resource editor.

BTW, SetIcon() may not be the ideal solution if you actually have more icon sizes. In that case SetIcons() could be better, see e.g. here viewtopic.php?f=23&t=43475#p177302
Post Reply