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.
Embed and set main icon using VC++
-
- Experienced Solver
- Posts: 60
- Joined: Thu Sep 06, 2012 8:00 pm
-
- Experienced Solver
- Posts: 60
- Joined: Thu Sep 06, 2012 8:00 pm
Re: Embed and set main icon using VC++
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.
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.
-
- Experienced Solver
- Posts: 60
- Joined: Thu Sep 06, 2012 8:00 pm
Re: Embed and set main icon using VC++
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,
Very hackish, but it worked.
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));
Re: Embed and set main icon using VC++
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
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