C++ 如何将图标分配给 Windows(或 Visual Studio)上的可执行文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4213938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to assign an icon to an executable on windows (or visual studio)
提问by Arthur
I would like to use a custom icon (a .ico file) for an executable, on windows (XP). The executable is a C++ program created thanks to visual studio (2008).
我想在 Windows (XP) 上为可执行文件使用自定义图标(.ico 文件)。可执行文件是由 Visual Studio (2008) 创建的 C++ 程序。
How can I change the icon from the executable, to the .ico file I want?
如何将图标从可执行文件更改为我想要的 .ico 文件?
回答by Arthur
Has mentioned in the comment, it is a duplicate question
已经在评论中提到,这是一个 重复的问题
Here is a copy paste of the answer from Jason Stevenson:
这是杰森史蒂文森答案的复制粘贴:
First go to Resource View (from menu: View --> Other Window --> Resource View). Then in Resource View navigate through resources, if any. If there is already a resource of Icon type, added by Visual Studio, then open and edit it. Otherwise right-click and select Add Resource, and then add a new icon.
Use the embedded image editor in order to edit the existing or new icon. Note that an icon can include several types (sizes), selected from Image menu.
Then compile your project and see the effect.
首先转到资源视图(从菜单:视图--> 其他窗口--> 资源视图)。然后在资源视图中浏览资源(如果有)。如果已有 Visual Studio 添加的 Icon 类型的资源,则打开并编辑它。否则右键单击并选择添加资源,然后添加一个新图标。
使用嵌入式图像编辑器来编辑现有的或新的图标。请注意,图标可以包括多种类型(大小),从图像菜单中选择。
然后编译你的项目,看看效果。
回答by Vladimir Panteleev
You can use a program such as Resource Hackerto edit resources (including icons) of Windows executables.
您可以使用诸如Resource Hacker 之类的程序来编辑 Windows 可执行文件的资源(包括图标)。
回答by engf-010
Assuming you have a "resource.h" and a ".rc"-file ,you define a identifier in "resource.h" (lets call it IDI_MY_ICON) and then add a line in the icon-section of your rc-file like IDI_MY_ICON ICON "myicon.ico"
as the first icon (thus this line must preceed any other ICON lines). Rebuild ,that's it.
假设你有一个“resource.h”和一个“.rc”文件,你在“resource.h”中定义一个标识符(我们称之为IDI_MY_ICON),然后在你的rc文件的图标部分添加一行IDI_MY_ICON ICON "myicon.ico"
作为第一个图标(因此该行必须在任何其他 ICON 行之前)。重建,就是这样。
回答by Migol
In C# projects you right clink on project that creates .exe file, select Properties and on the first screen you can set icon. Not sure if this works for C++ but the properties panel is the place that you should look in.
在 C# 项目中,您右键单击创建 .exe 文件的项目,选择属性,然后在第一个屏幕上设置图标。不确定这是否适用于 C++,但属性面板是您应该查看的地方。
回答by Honnes
You should be able find it at the 'Properties' of your project. (By rightclicking your project name). It's on the Application Tab, at least, in Visual Studio 2008 working in C# it is, and scrolling down there a bit.
您应该可以在项目的“属性”中找到它。(通过右键单击您的项目名称)。它在应用程序选项卡上,至少在使用 C# 的 Visual Studio 2008 中是这样,并且向下滚动一下。