30

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

Community
  • 1
  • 1
Danny
  • 313
  • 1
  • 3
  • 4

6 Answers6

44

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.
Community
  • 1
  • 1
CaptainBli
  • 4,121
  • 4
  • 39
  • 58
  • 2
    I didn't need to go beyond adding the resource to the project. – BuvinJ Jul 22 '15 at 19:36
  • 1
    It seems that in steps described, once the icon is added in the "Resource View", rather than manually editing the `.rc` file, just renaming an added icon to "MAINICON" should work. – CJBS Aug 28 '15 at 18:13
23

Right-click on your project, and select Add -> Resource. Then select Icon and click New. Edit your icon, and you should be good to go.

Ben
  • 1,003
  • 1
  • 11
  • 18
12

See resource.rc in your application.

#define IDI_ICON_1            102
#define IDI_ICON_2            103

// Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems.

IDI_ICON_1            ICON                    "icoMainApp.ico"
IDI_ICON_2            ICON                    "iconSecond.ico"
Shaggy
  • 121
  • 1
  • 2
1

Simply add the icon.ico and a file resource.rc to the project:

#define APSTUDIO_READONLY_SYMBOLS
#include "winres.h"
#undef APSTUDIO_READONLY_SYMBOLS

MAINICON ICON "icon.ico"

VS_VERSION_INFO VERSIONINFO
    FILEVERSION 0,0,0,0
    PRODUCTVERSION 0,0,0,0
    FILEFLAGSMASK 0x3FL
    FILEFLAGS 0x0L
    FILEOS 0x4L
    FILETYPE 0x1L
    FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904E4"
        BEGIN
            VALUE "CompanyName", "..."
            VALUE "FileDescription", "..."
            VALUE "FileVersion", "0.0.0.0"
            VALUE "InternalName", "..."
            VALUE "LegalCopyright", "© ..."
            VALUE "OriginalFilename", "..."
            VALUE "ProductName", "..."
            VALUE "ProductVersion", "0.0"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1252
    END
END

More details can be found here.

ProjectPhysX
  • 4,535
  • 2
  • 14
  • 34
0

try to add a resource file to your project, then you should be able to open the rc file and add an icon

user287107
  • 9,286
  • 1
  • 31
  • 47
0

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

#ifndef _resource_rc
#define _resource_rc

MAINICON ICON "icon.ico" //If you can set any name


#endif // _resource_rc

Save and rebuild this project. Happy coding

Sajjad Hosen
  • 71
  • 1
  • 6