App Icon for C++ project
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.
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.
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
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.)
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.