4

I was wondering if there was a way to change the default icon that VS2012 makes when I compile my app. Just for those wondering, I am trying to change the .exe program's icon, not the window icon at the top left of the window and on the start menu. I already know how to do that. I have been Google-ing this for ever and it always shows up how to change the window icon, not the actual file's icon. Thanks in advance!!!

EDIT: This is what I want to do...

I want to replace this...

enter image description here

with this...

enter image description here]

Thanks, hope this clarifies.

Garrett Ratliff
  • 309
  • 3
  • 5
  • 10

4 Answers4

5

Adding icon to executable

Tested for VS2012 Express

Create a icon.rc file next to your .vcxproj file and fill it with the following text:

// Icon Resource Definition
#define MAIN_ICON                       102
MAIN_ICON               ICON                    "your_icon.ico"

Then add the following to your .vcxproj file anywhere within the Project tag:

<ItemGroup>
    <ResourceCompile Include="icon.rc">
    </ResourceCompile>
</ItemGroup>

Additional options

If you want you may forward definitions to your icon.rc file like so:

<ItemGroup>
    <ResourceCompile Include="icon.rc">
        <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">/D_DEBUG %(AdditionalOptions)</AdditionalOptions>
    </ResourceCompile>
</ItemGroup>

Notice the /D_DEBUG definition, which defines _DEBUG for your resource file. Then within your icon.rc file check for definitions normally:

#define MAIN_ICON 102
#if defined(_DEBUG)
MAIN_ICON               ICON                    "debug_icon.ico"
#else
MAIN_ICON               ICON                    "release_icon.ico"
#endif
Sergio Basurco
  • 3,488
  • 2
  • 22
  • 40
  • Are you using VS2012 Express with a c++ project? – Sergio Basurco May 20 '15 at 15:05
  • Your code had no mention of LoadImage or LoadIcon, which I later discovered was necessary to make this work. Your answer is incomplete and therefore nearly useless. – Andrew May 21 '15 at 09:44
  • I just tried with a project from scratch and it worked. If possible post how to reproduce your case, feel free to edit this answer to add any other info or post another answer. Note I have only tested this for VS2012 Express with console c++ applications. – Sergio Basurco May 21 '15 at 15:04
2
  1. Add an icon in the resource section of you C++ project. This icon will be shown as an Application icon for your executable. [Note: make sure you are in the Resource View window, not the Solution Explorer window. Then right-click on the rc folder to Add Resource...]

  2. I have tried this with Win32 Console Application and it shows the icon in the Explorer as Application Icon. This should work with other types of applications also.

  3. Also note that while adding the icon you need to add different size images for the Icon like 16*16, 32*32. These different icon images will be used by Windows Explorer to display Application Icon in different View Modes(Small Icons, Medium Icons, Larget Icons, Extra Large icons etc.)

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
Pruthviraj
  • 131
  • 3
1

This is not really how it works. The size of the icon of your program as displayed by Windows isn't determined by you, the user selects it. It is a user preference, very simple to change on later Windows versions by just rolling the mouse scroll button on the desktop. And an icon doesn't have just a single size, it is capable of storing multiple images. Windows picks the one that fits best. And the one you get when starting a new project is just a stock one that's stored in the project template. You can change it by tinkering with the project template .zip file but that's kinda pointless, you want to give your program a custom icon that personalizes it.

Best thing to do is to steal, beg or borrow one, making a good looking icon is an art. Lots of web sites where you can download free ones. If you want to take a shot at creating your own then that's supported as well. Simply double-click the project's .rc file to open the resource view, open the Icon node and double-click the default icon to open the icon editor. You add a new size with Image + New Image Type. Plenty of freeware icon editors available as well.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Where is the .rc file?? I have looked all over the project file and I cannot find the .rc file anywhere. Does VS2012 still use .rc files or maybe it is something with the settings?? Could it be the settings that don't allow me to make .rc files?? I am also using the express edition. Is it something with the express edition that won't make an .rc file?? I remember having that file in VS2008 and 2010 but it is not in VS2012. Thanks in advance. – Garrett Ratliff Apr 16 '13 at 15:00
  • I don't know, maybe you forgot to create one. The default "Win32 Project" project template certainly creates one. – Hans Passant Apr 16 '13 at 15:37
  • I read that it won't make the .rc files anymore on the express editions. That stinks. Do you have any other suggestions?? – Garrett Ratliff Apr 16 '13 at 16:06
0

If its a Win32 application then you can add a resource to your project and then put the icon in there. Then you can assign the icon to your application by sending the WM_SETICON method. For MFC applications, resources are already present and there is a nominated icon resource that you can just change.

You can also load it directly from an external file as suggested here:

Setting program icon without resources using the WIN32 API

I would recommend the resource route though. Resources get embedded in your executable and it is the recommended way to do this sort of thing in Win32 and MFC.

Community
  • 1
  • 1
GlGuru
  • 756
  • 2
  • 10
  • 21