Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

c++ - Set an exe icon for my program

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?

http://i46.tinypic.com/nd7m8z.jpg

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

  1. 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.

  2. 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.

  3. 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:

  1. Sometimes when running from Visual Studio you will not get the icon while debugging.
  2. 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 utilities that convert images to .ico files. as quoted from bobobobo.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...