How can I add an icon to my MinGW compiled program for Windows?

  • Thread starter Coin
  • Start date
In summary: I just used the CMake GUI to add a resource file called "icon.ico" to the project, and then set the icon property in the main CMakeLists.txt file. Then I just included the icon.ico file in the distribution package.In summary, the person is developing a program for Windows and Mac, but is on a Mac and installs MinGW to compile Windows .exe's on their Mac. They can't figure out how to associate a .ico file with their Windows .exe. They use code blocks and Mingw under windows to generate a gui application and include the icon file as a resource.
  • #1
Coin
566
1
Okay, here's one.

- I'm developing a program for macintosh+windows.
- But, I myself am on a macintosh.
- So, I installed MinGW on my mac. Now, I can compile Windows .exes sitting here on my macintosh. (This part already works.)
- But I can't figure out: How do I give my program an icon?

I have here a .ico I made, but I don't know how to associate it with or embed it into my Windows .exe. I don't really know how Windows icons work. Is there a way to do this using mingw or any open source tool I can run on my mac? (I.E. what I'm trying to do somehow prep the exe is so that when I zip it up and send it over to a windows machine, the windows user will see the icon immediately.)
 
Technology news on Phys.org
  • #2
It is a GUI app or Console app?
You should try some windows API function such as LoadIcon. You should read books such as <<windows programming>> by Charles Petzold.
 
  • #3
It is a normal type gui app.

I'm not sure what you mean about the API? I don't mean I want to change the icon at runtime, I mean like I want some file to be the program's icon even before it launches and I can't do the normal thing of right click->properties because I'm not actually on windows myself.
 
  • #4
Oh, I'm using code::blocks and Mingw under windows, so, with application wizard, it is easy to generate a gui application.
You can use include an icon file as it's resource file.
That all I know.
 
  • #5
OK. Thanks for the help.

It turns out that the correct answer if you're limited to the command line tools is to http://www.cyrocom.co.uk/tutorials/cpp/icon.html [Broken]. I got it working using this.
 
Last edited by a moderator:
  • #6
Hi. Actually the http://blog.stranadurakov.com/2009/04/27/icon-and-version-information-resource-file/" [Broken] is pretty easy.
 
Last edited by a moderator:

1. How do I add an icon to my program in mingw?

To add an icon to your program in mingw, you will need to use a resource file. This file will contain the icon image and information about where to place it in your program. Once you have created the resource file, you can use the "windres" command to compile it and add it to your program.

2. Can I use any image format for my icon in mingw?

No, mingw only supports icons in the .ico format. If you have an image in a different format, you will need to use an image converter or editor to save it as an .ico file before adding it to your program.

3. How do I specify which icon to use for my program in mingw?

In your resource file, you can specify which icon to use by giving it a unique identifier and using that identifier in the "ICON" statement. You can also specify the size and color depth of the icon using additional parameters in the "ICON" statement.

4. Can I use multiple icons for different resolutions in my program in mingw?

Yes, you can include multiple icons of different resolutions in your resource file and specify which one to use for different screen resolutions. This can be done by using the "IDI_APPLICATION" identifier and adding additional icons with the appropriate identifiers and resolution specifications.

5. Are there any limitations to adding an icon in mingw?

One limitation of adding an icon in mingw is that it can only be displayed in the Windows environment. If you want your program to run on other operating systems, you will need to use a cross-platform solution for adding an icon.

Similar threads

  • Programming and Computer Science
Replies
1
Views
271
  • Programming and Computer Science
Replies
25
Views
2K
  • Programming and Computer Science
Replies
29
Views
2K
  • Programming and Computer Science
Replies
14
Views
1K
  • Programming and Computer Science
Replies
19
Views
2K
  • Programming and Computer Science
Replies
15
Views
4K
  • Computing and Technology
Replies
3
Views
968
Replies
6
Views
1K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
19
Views
3K
Back
Top