Make Ico icon file
Edit the image material, cut it into a square, and then convert it into an ico
icon
Put the ico icon file in the previously written startprintservices.cpp
file directory
Create resource files
Then we create a file named ico.rc
as and add the following content:
A ICON "myicon.ico"
Use windres to link rc files, the link output file extension is .o
windres -i ico.rc -o ico-out.o
Assemble compilation
We compile again and put the resource files into it, and the generated exe program file can display icons at this time.
g++ startprintservices.cpp ico-out.o -o startprintservices.exe
Windress Command Introduction
windres is a Windows resource compiler for compiling Windows resource files (.rc) into COFF object files (.obj) or Windows resource files (.res).
It is part of the MinGW toolchain and can be used by the Visual C++ compiler.
The common command format of windres:
windres [options] input-file
input-file is the .rc resource file to be compiled. Common options include:
- o <output-file> :设置输出文件的名称。默认为input-file.obj或input-file.res。
- O <output-format> :设置输出文件格式。可以是obj(默认)、res或coff。
- i <include-path> :添加包含路径。用于搜索的.h头文件。
- I <resource-include-path> :添加资源包含路径。用于搜索的.rc资源文件。
- v :输出详细信息。用于调试。
For example, if there is a resource.rc
resource file, resource.res
the command to compile it is:
windres resource.rc -O res -o resource.res
In addition, if the resource file refers to the resource definition file resource.h
, you need to specify the header file path when compiling:
windres resource.rc -O res -o resource.res -i D:\Code\include
Windres is commonly used in:
- Compilation of Windows resource files. It can compile .rc files into .obj object files or .res resource files, and then link them into the application.
- Compile resource files when developing Windows applications with non-Microsoft toolchains such as MinGW or Cygwin.
- When manually developing and compiling resources, using windres directly can save the resource editor of the IDE.
- Compile and link resource files at the command line when building scripts or makefiles.