之前写了个滑动拼图游戏,编译出来的Win32可执行文件是没有图标的:http://7xibui.com1.z0.glb.clouddn.com//2016/04/24/QQ%E6%88%AA%E5%9B%BE20160424120224.png

查了下资料,增加了图标:

http://7xibui.com1.z0.glb.clouddn.com//2016/04/24/QQ%E6%88%AA%E5%9B%BE20160424123454.png

下面说下具体步骤:

创建rc文件

首先创建.rc文件,添加如下内容:

id ICON "slidepuzzle.ico"
VERSIONINFO
FILEVERSION     1,1,0,0
PRODUCTVERSION  1,1,0,0
BEGIN
  BLOCK "StringFileInfo"
  BEGIN
    BLOCK "040904E4"
    BEGIN
      VALUE "CompanyName", "Netcan Soft"
      VALUE "FileDescription", "Sliding Puzzle"
      VALUE "FileVersion", "1.1"
      VALUE "InternalName", "slidepuzzle"
      VALUE "LegalCopyright", "Netcan Soft"
      VALUE "OriginalFilename", "slidepuzzle.exe"
      VALUE "ProductName", "SlidePuzzle"
      VALUE "ProductVersion", "1.1"
    END
  END

  BLOCK "VarFileInfo"
  BEGIN
    VALUE "Translation", 0x409, 1252
  END
END

根据相关字段进行修改即可,ICON指定了图标。

导出.res文件

windres my.rc -O coff -o my.res

编译可执行文件

g++ -o my_app obj1.o obj2.o my.res