为我的程序设置一个 exe 图标
我正在使用 Microsoft Visual Studio 2008,并且正在尝试为我的程序设置 exe 图标。
我搜索了这个网站并发现了这个: 如何在 Visual Studio 2008 中设置应用程序的图标?
但我找不到这个“资源视图”。我已经查看了 MVS08 中的所有内容。
如何访问资源视图并为我的应用程序设置主图标?
I'm using Microsoft Visual Studio 2008 and I'm trying to set an exe icon for my program.
I've searched this site and found this: How do I set the icon for my application in visual studio 2008?
But I can't find this "Resource View". I've looked everywhere in MVS08
How may I access Resource View and set the main icon for my application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在 Tymek 的帮助下,Ben 的问题有了一个良好的开端,但您需要进行下一步。将图标添加到资源后,您还需要一个资源文件
.rc
才能将图标设置为应用程序的主图标。如果您不知道是否已有资源文件,请打开项目的资源视图:转到视图->资源视图或Ctrl+ Shift+E(在 Visual Studio 2012/2013 中视图 -> 其他 Windows-> 资源视图 或者您可以键入 Ctrl +W,R 打开它,在 2015 中 Ctrl+Shift+E)。检查您是否有 MyProject->MyProject.rc。您应该在此处
添加
您的图标。然后它应该为您创建一个资源文件。现在按 Ctrl+Shift+F 搜索整个解决方案。搜索您的图标文件名,以便可以打开实际的
.rc
文件。当您这样做时,它可能会建议您已经打开它,只需接受即可。现在找到一个位置,将以下行添加到
.rc
文件中:MAINICON ICON "foo.ico"
下次编译时,您可以浏览到包含可执行文件的文件夹,并看到您有与该应用程序关联的图标,当您从那里运行它时,它将使用该图标。
注意:
.ico
文件。您不能使用 PNG 图像文件作为可执行文件的图标,它将不起作用。您必须使用.ico
。有一些网络实用程序可以将图像转换为 .ico 文件。引用自 bobobobo。Ben had a good start to the question along with the help of Tymek, but you need to go to the next step. Once you have added your icon to your resources, you will also need a resource file
.rc
in order to set the icon as the main icon of your application.If you don't know if you already have a resource file, open your Resource View for the project: go to View->Resource View or Ctrl+Shift+E (in Visual Studio 2012/2013 View->Other Windows->Resource View or you can type Ctrl+W,R to get it to open and in 2015 Ctrl+Shift+E). Check to see if you have a MyProject->MyProject.rc. This is where you should
Add
your icon. It should then create a resource file for you.Now Ctrl+Shift+F to search the whole solution. Search for your icon filename so that you can open the actual
.rc
file. When you do so it may suggest that you already have it open just accept.Now find a place to add the following line to the
.rc
file:MAINICON ICON "foo.ico"
The next time you compile you can browse to the folder with the executable and see that you have the icon associated with the app and when you run it from there it will use the icon.
Note:
.ico
file. You cannot use a PNG image file for your executable's icon, it will not work. You must use.ico
. There are web utilities that convert images to .ico files. as quoted from bobobobo.右键单击您的项目,然后选择
添加
->资源
。然后选择图标
并单击新建
。编辑你的图标,你就可以开始了。Right-click on your project, and select
Add
->Resource
. Then selectIcon
and clickNew
. Edit your icon, and you should be good to go.请参阅应用程序中的resource.rc。
// ID值最低的图标放在最前面,以确保应用程序图标
// 在所有系统上保持一致。
See resource.rc in your application.
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
只需将
icon.ico
和文件resource.rc
添加到项目中即可:更多详细信息可以在 此处。
Simply add the
icon.ico
and a fileresource.rc
to the project:More details can be found here.
尝试将资源文件添加到您的项目中,然后您应该能够打开 rc 文件并添加图标
try to add a resource file to your project, then you should be able to open the rc file and add an icon
在项目文件夹下创建resources.h文件,会自动创建新的资源文件夹。 resources.h可以在源文件下面的资源文件中找到。
Icon.ico 文件放在项目文件或其他位置选择的位置文件夹中。
编写以下代码
保存并重建该项目。快乐编码
Create a resources.h file under the project folder and the new resource folder will be created automatically. And resources.h can be found in the resource file below the source files.
Icon.ico file put in the project file or another location select the location folder.
Write the following code
Save and rebuild this project. Happy coding