App Icon for C++ project

I simply want to change the icon used by my /clr .exe. (The icon that appears in Windows Explorer with the file).

My web search so far has shown that other Visual Studio users, perhaps using VB or C#, can just set the icon in their project settings. I can not find the option they describe.

[293 byte] By [GregDude] at [2007-12-16]
# 1
Explorer displays the first icon resource image in the .exe whose size matches the current explorer view. For example, if you select View\Details in Explorer it will look for a 16x16 image in the first icon resource in the .exe. If you select View\Icons, it will look for a 32x32 image. If it can't find an exact match, it will try to synthesize one from the closest matching image.

In C# or VB, the compilers will set the icon for you from project settings but C++ projects have traditionally allowed you to edit all the resources in your project and provided the editors to do so right in the IDE.

In order to change the Details View icon image Explorer shows for a Visual C++ wizard-generated Winforms app (which by default provides you with an icon with 16x16 and 32x32 images), you can go into the resource view and select the 16x16 image for the app.ico icon (From the main menu after clicking in the icon editor window: Image\Current Icon Image Types\16x16, 16 colors). Edit that icon and rebuild your project.

If you want that icon to appear on the caption bar of your winforms app, bring up the Properties window with the main form selected in the Winforms designer window and set the Icon property.

Hope this helps,

-Ron Pihlgren
VC++ Testing

RonPihlgren at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 2

Ok, I did all you suggested. The designer added the line:

this->Icon = (cli:: safe_cast<System:: Drawing::Icon^ >(resources->GetObject(L"$this.Icon")));

I made absolute certain I had both a 16x16 and a 32x32 icon from my Main Form's solution explorer,

"Resource File", app.ico. And if I look at the folder with explorer, I can see the file app.icon.

Yet, with the line in the designer, my application crashes on this line. If I delete the line added by the

designer, than the application works. I have managed to get all my icons corrected (that shown next

the application in different explorer options); but can not get the icon in the upper left corner of the

main form to change. (MS VS C++ 2005 Version 2.0.50727). Pure .Net application (no native C++).

The Error:

An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll

Additional information: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "WSColorApp.MainForm.resources" was correctly embedded or linked into assembly "ColorApp" at compile time, or that all the satellite assemblies required are loadable and fully signed.

(Even though I checked "This post contains a code sample, I had to follow the ::'s with spaces to

avoid smillies.)


WedgeSoft at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 3

I added the folowing two lines to my main forms construtor:

System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MainForm::typeid));

this->Icon = gcnew System:: Drawing::Icon(L"<path>\\app.ico");

(where <path> is an absolute path on my system.)

The above worked. But, if anyone knows... How do I get the designer code to work? And, am I doing myself any harm by using an absolute path? I am thinking the resource gets loaded into the assembly, and the fact that it is loaded from an absolute path is not a concern.

WedgeSoft at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...