CodeBlocks - How to add an icon to a C program?

冷暖自知 提交于 2019-11-28 04:30:00

问题


I have a small C console program and I want to add an .ico file to it, so that the executable looks nice.

How can I do this in CodeBlocks with MinGW/gcc?


回答1:


I could not find relevant help via google that a total beginner (like me for C) could follow, so I will Q&A this topic.

  • First of all you need an .ico file. Put it in the folder with your main.c file.
  • In CodeBlocks go to File -> New -> Empty File and name it icon.rc. It has to be visible in the Workspace/Project otherwise CodeBlocks will not be aware of this file. It will show up there in a project folder called Resources .
  • Put the following line in it: MAINICON ICON "filename.ico". MAINICON is just an identifier, you can choose something different. More info 1 & More info 2.
  • Save the files and compile - CodeBlocks will do everything else for you

What will happen now, is windres.exe (the Resource Compiler) compiling the resource script icon.rc and the icon to an object binary file to obj\Release\icon.res. And the linker will add it to the executable.

It's so easy yet it took me quite a while to find it out - I hope I can save someone else having the same problem some time.



来源:https://stackoverflow.com/questions/49164595/codeblocks-how-to-add-an-icon-to-a-c-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!