[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 567
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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