• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 578
  • Last Modified:

C++ Give Executable File An Icon

I'm making a program in C++ thats just an exe file but the Windows default icon looks rather boring. Is there some way to code the icon into the program without requiring extra files to go with the exe?
0
Cyber-Dragon
Asked:
Cyber-Dragon
  • 6
  • 5
1 Solution
 
evilrixSenior Software Engineer (Avast)Commented:
The icon and be added as an embedded resource. How this is done depends on what type of application you are developing. Is it an MFC, WinForms, WPF, Win32? Each of these will have different mechanisms for doing this.
0
 
jkrCommented:
You can add such an icon by creating a .rc file and add that one to your project. Make sure that the icon file (.ico) resides in the same directory. That .rc file (myapp.rc) looks like
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
 
1       ICON                    "myapp.ico"

Open in new window

0
 
Cyber-DragonAuthor Commented:
Sorry for the delay.

I'm making a Windows application from scratch.

jkr, with the solution you gave me will I have to move the ico file with my executable?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
jkrCommented:
No, not necessary. Dureing the build process (while the resource compiler processes the .tc file), it'll be embedded into the executable. See e.g. http://msdn.microsoft.com/en-us/library/aa381018(VS.85).aspx ("Icon Resource")
0
 
Cyber-DragonAuthor Commented:
And this can be defined anywhere in the program?
0
 
jkrCommented:
No, you need to put that into a separate file with an .rc extension which you add to you project. These files can not only contain icons, but also, bitmaps, string tables etc., see http://msdn.microsoft.com/en-us/library/aa380599.aspx ("About Resource Files")
0
 
Cyber-DragonAuthor Commented:
I created a .rc file with notepad, put the code into it and put the icon file in the folder. But now when I compile, the executable is not in the release or debug folders.
0
 
jkrCommented:
Any build errors in the oputput window? And, more important: Have you added the .rc file to your solution?
0
 
Cyber-DragonAuthor Commented:
No build errors and yes I did.

1>Compiling resources...
0
 
jkrCommented:
OK, that seems allright. Could you post the whole BuildLog?
0
 
Cyber-DragonAuthor Commented:
Its ok I figured out what I was doing wrong.

I was in the wrong folder.

The project has two sets of Realese and Debug folders and I was in the one to deep.
0
 
Cyber-DragonAuthor Commented:
Read the entire post on instructions on how to create the .rc file.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now