7

I've seen this documentation for C#/Visual Basic application icons, but there is nothing I can find for how to do this with the C++ version.

This StackOverflow question is for Visual Studio 2008, not 2019. This one is also obsolete, as it works for Visual Studio 2017 but not Visual Studio 2019.

drescherjm
  • 10,365
  • 5
  • 44
  • 64
Sciborg
  • 416
  • 1
  • 4
  • 15
  • 2
    You need to add an icon resource\ to the project – Govind Parmar Jun 28 '20 at 00:18
  • Can you explain what you mean and how to do this? – Sciborg Jun 28 '20 at 00:19
  • 3
    @Sciborg How is [that one](https://stackoverflow.com/questions/45246739/visual-studio-2017-specify-an-app-icon) obsolete? Alternatively, just create a default Windows Desktop app, which the VS wizard generates with an `.rc` file and a stock `.ico` icon. – dxiv Jun 28 '20 at 00:47
  • @dxiv It no longer works for the 2019 version as far as I know. It only works for the 2017 version. And I cannot really create a default Windows Desktop app due to the nature of the project, but that is a good suggestion and would be helpful for other people with this question. – Sciborg Jun 28 '20 at 00:54
  • 1
    @Sciborg It does work, like it did in previous versions. Try it. – dxiv Jun 28 '20 at 01:11
  • 1
    Never mind, I figured it out. I'll answer myself with how I did it. Thanks. – Sciborg Jun 28 '20 at 01:29
  • 2
    Does this answer your question? [Visual Studio 2017 - Specify an App Icon](https://stackoverflow.com/questions/45246739/visual-studio-2017-specify-an-app-icon) – Daniel A. White Jun 28 '20 at 01:33
  • Resources are managed using a [resource definition file](https://learn.microsoft.com/en-us/windows/win32/menurc/about-resource-files). This is a simple text-based format, that's translated by the [Resource Compiler](https://learn.microsoft.com/en-us/windows/win32/menurc/resource-compiler) into a binary format that ultimately gets picked up by the linker. To add application icons, simply place the respective statements into an .rc file, and optionally provide a C++ header file that contains symbolic constants for the IDs, if you want to share those with application code. – IInspectable Jun 28 '20 at 08:58

1 Answers1

15

After some fiddling I figured it out. This answer for VS2017 was basically correct, but it didn't fully explain what you have to do to get it to work and the documentation it links to was vague enough to confuse me, so I'll post this answer as the VS2019 version with full and complete easy-to-follow instructions.

  1. Navigate to your Solution Explorer tab.

  2. Find the Resource Files folder in your project, probably near your Header Files and Source Files folders.

  3. Right-click on the Resource Files folder and select "Add > Resource."

  4. In the "Add Resource" window that pops up, select Icon and select Import.

  5. Import either a bitmap file or your custom .ico file.

  6. Now a Resource File (.rc) is created which contains your application Icon, in the form of an Icon node. Click on that .rc file to open the Resource View tab.

  7. You'll see that there's a folder called Icon. It should contain your new icon.

If it contains a default Icon file, probably named IDI_ICON1, you'll have to edit that node to make it the icon you want to use. I don't know why it does that.

Sciborg
  • 416
  • 1
  • 4
  • 15
  • 1
    You could also feel free to [Accept Your Own Answers](https://stackoverflow.blog/2009/01/06/accept-your-own-answers/). – Drake Wu Jul 09 '20 at 06:40
  • 1
    I tried creating an icon with id of IDI_ICON1. But the output file is still showing default icon. My project is for a C++ native OCX in VS2019 and it did not have an IDI_ICON1 icon before I created one. Is the id IDI_ICON1 a special id that is always used for the application icon? Or is there someplace the application icon id has to be set to IDI_ICON1? Or is it because my project is for an OCX output file? The icon it is showing is two gears which is default for OCX file I believe. – JonN Sep 29 '21 at 19:36