C++ 如何在 Visual Studio 2008 中为我的应用程序设置图标?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/320677/
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 do I set the icon for my application in visual studio 2008?
提问by Ronny Vindenes
How do I set the executable icon for my C++ application in visual studio 2008?
如何在 Visual Studio 2008 中为我的 C++ 应用程序设置可执行图标?
采纳答案by 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.
首先转到资源视图(从菜单:视图--> 其他窗口--> 资源视图)。然后在资源视图中浏览资源(如果有)。如果已有 Visual Studio 添加的 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.
然后编译你的项目,看看效果。
See: http://social.microsoft.com/Forums/en-US/vcgeneral/thread/87614e26-075c-4d5d-a45a-f462c79ab0a0
请参阅:http: //social.microsoft.com/Forums/en-US/vcgeneral/thread/87614e26-075c-4d5d-a45a-f462c79ab0a0
回答by bobobobo
This is how you do it in Visual Studio 2010.
这就是您在 Visual Studio 2010 中的做法。
Because it is finicky, this can be quite painful, actually, because you are trying to do something so incredibly simple, but it isn't straight forward and there are many gotchas that Visual Studio doesn't tell you about. If at any point you feel angry or like you want to sink your teeth into a 2 by 4 and scream, by all means, please do so.
因为它很挑剔,所以这可能会很痛苦,实际上,因为您正在尝试做一些非常简单的事情,但这不是直接的,而且还有很多 Visual Studio 没有告诉您的问题。如果您在任何时候感到生气或想咬牙切齿地打成 2 x 4 并尖叫,请务必这样做。
Gotchas:
陷阱:
- You need to use an .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 utilitiesthat convert images to .ico files.
- The ico used for your exe will be the ico with the LOWEST RESOURCE ID. In order to change the .ico
- 您需要使用 .ico 文件。 您不能为可执行文件的图标使用 PNG 图像文件,它不起作用。您必须使用 .ico。有一些网络实用程序可以将图像转换为 .ico 文件。
- 用于您的 exe 的 ico 将是具有最低资源 ID 的 ico。为了改变.ico
1) Open VIEW> RESOURCE VIEW(in the middle of the VIEWmenu), or press Ctrl+Shift+Eto get it to appear.
1) 打开VIEW> RESOURCE VIEW(在VIEW菜单中间),或按Ctrl+ Shift+E使其出现。
2) In Resource view, right click the project name and say ADD> RESOURCE...
2) 在资源视图中,右键单击项目名称并说添加>资源...
3) Assuming you have already generated an .ico file yourself, choose Iconfrom the list of crap that appears, then click IMPORT.
3) 假设您自己已经生成了一个 .ico 文件,从出现的废话列表中选择Icon,然后单击IMPORT。
4) At this dialog *.ico
files aren't listed, and you can'tuse a regular PNG or JPG image as an icon, so change the file filter to *.ico
using the dropdown. Misleading UI, I know, I know.
4) 在此对话框*.ico
中未列出文件,并且您不能使用常规的 PNG 或 JPG 图像作为图标,因此将文件过滤器更改为*.ico
使用下拉列表。误导性用户界面,我知道,我知道。
5) If you compile your project now, it will automaticallystick the .ico with the lowest ID(as listed in resource.h
) as the icon of your .exe file.
5) 如果您现在编译您的项目,它会自动粘贴具有最低 ID(如 中所列resource.h
)的 .ico作为您的 .exe 文件的图标。
6) If you load a bunch of ICO files into the project for whatever reason, be sure the .ico you want Visual Studio to use has the lowestid in resource.h
. You can edit this file manually with no problems
6)如果加载了一堆的ICO文件添加到项目无论出于何种原因,可以肯定你想Visual Studio来使用.ICO具有最低的ID resource.h
。您可以毫无问题地手动编辑此文件
Eg.
例如。
//resource.h
#define IDI_ICON1 102
#define IDI_ICON2 103
IDI_ICON1 is used
使用 IDI_ICON1
//resource.h
#define IDI_ICON1 106
#define IDI_ICON2 103
Now IDI_ICON2 is used.
现在使用 IDI_ICON2。
回答by ravenspoint
The important thing is that the icon you want to be displayed as the application icon ( in the title bar and in the task bar ) must be the FIRST icon in the resource script file
重要的是,您希望作为应用程序图标(在标题栏和任务栏中)显示的图标必须是资源脚本文件中的第一个图标。
The file is in the res folder and is named (applicationName).rc
该文件位于 res 文件夹中,并命名为 (applicationName).rc
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
(icon ID ) ICON "res\filename.ico"
回答by Cretzu
You add the .ico in your resource as bobobobo said and then in your main dialog's constructor you modify:
您像 bobobobo 所说的那样在资源中添加 .ico,然后在主对话框的构造函数中进行修改:
m_hIcon = AfxGetApp()->LoadIcon(ICON_ID_FROM_RESOURCE.H);
m_hIcon = AfxGetApp()->LoadIcon(ICON_ID_FROM_RESOURCE.H);
回答by Jon
I don't know if VB.net in VS 2008 is any different, but none of the above worked for me. Double-clicking My Projectin Solution Explorer brings up the window seen below. Select Applicationon the left, then browse for your icon using the combobox. After you build, it should show up on your exe file.
我不知道 VS 2008 中的 VB.net 是否有任何不同,但以上都不适合我。在解决方案资源管理器中双击“我的项目”会出现如下所示的窗口。选择左侧的应用程序,然后使用组合框浏览您的图标。构建后,它应该显示在您的 exe 文件中。
回答by Jon
If you're using .NET, in the solutions explorer right click your program and select properties. Under the resource section select Icon and manifest, then browse to the location of your icon.
如果您使用的是 .NET,请在解决方案资源管理器中右键单击您的程序并选择属性。在资源部分下选择图标和清单,然后浏览到您的图标的位置。