C++ - OpenGL - Adding an icon to the executable with Visual Studio

To have an executable file that seems professional, it's necessary to have your own icon when someone launches your program.

This tutorial could easily adapted to any application generated from Visual Studio on Windows.

This icon is generally the logo of the software, game or application you created.

First of all

Creating an ICO file

The icon for the program must be an ICO format.

It means that the extension must be .ico, like for example icon.ico.

The name is free, but the extension is not.

This extension has to be a real ICO format and for that you have to generate this ICO file from a PNG.

There are a lot of website that allow you to convert a PNG file into an ICO.

Just search on your favorite search engine with this kind of research: png to ico.

Paths and directories project for this tutorial

To follow this tutorial, let's create a project from scratch or skip this part if you already created one with a previous OpenGL tutorial.

Open Visual Studio and create an empty project > File > New > Project > Templates > Visual C++ > Empty Project.

Then write:

  • Name: Shapes2D
  • Location: C:\dev\visual-studio-c++\
  • Solution: Create a new solution
  • Solution name: BadprogTutorial

OK > Finish.

Your Shapes2D project has been created into your BadprogTutorial solution.

Let's add a main.cpp > Right click your project > Add > New Item > Visual C++ > C++ File > write the name main.cpp > Add.

Visual Studio

From Visual Studio, open your project and right click Resource Files > Add > New Item > type a new name like badprog.rc > Add.

Now the file badprog.rc is in the virtual Resource Files directory.

You could find this file on your project directory:

  • C:\dev\visual-studio-c++\BadprogTutorial\Shapes2D

Add the icon.ico file inside this directory:

  • C:\dev\visual-studio-c++\BadprogTutorial\Shapes2D

You can't directly open this file, so still from your Solution > Right click badprog.rc > View Code.

As you can see the file is empty.

Then write inside:

  • BADPROG ICON "icon.ico"

Where:

  • BADPROG is the name of your resource
  • ICON is the type of your resource
  • "icon.ico" is the name of the resource

That's all!

Now build and launch your project.

Once done, you should see in the Debug directory, the Shapes2D.exe file with the icon that you've just added.

So at the end you should have the following arborescence from your project on Windows:

  • C:\dev\visual-studio-c++\BadprogTutorial\Shapes2D\
    • badprog.rc
    • icon.ico
    • main.cpp

And from Visual Studio:

  • Solution BadprogTutorial
    • Shapes2D
      • External Dependencies
      • Header Files
      • References
      • Resource Files
        • badprog.rc
      • Source Files
        • main.cpp

Once you've compiled your project, you should have, in your Debug directory, the final Shape2D.exe with your own icon.

Conclusion

You know now how to create your own icon for your executable file for your OpenGL program.

But not only because as said previously this tutorial works for every program you'll create with Visual Studio.

So, well done you've made it. laugh

 

Comments

Comment: 

Thanks a lot!
Found what I was looking for!

Comment: 

This was really helpful. This is the 5th site I visited in an attempt to customize my exe icon, and it was the first to work.

Comment: 

Thank you very much, this explanation was really helpful!

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.