954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to change icon of C++ console app

How do I change the icon of the exe. in console mode? (as part of the exe itself) :?:

CodeBoy101
Junior Poster in Training
71 posts since Dec 2007
Reputation Points: 8
Solved Threads: 0
 

You don't -- console programs do not have resources so its not possible to change an icon that doesn't exist.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 
You don't -- console programs do not have resources so its not possible to change an icon that doesn't exist.


That's not strictly true. If you have Microsoft Visual c++ (I use version 6), you can add resources to a console app. Just hit Ctrl+R to bring up your Insert Resource Dialog. Click on Import to select your icon or Icon to create an icon. Then go File - Save/Save All. Name it something like MyScript.rc or something like that. Then add it to the project by going to Project - Add to project - Files and select your MyScript.rc or whatever you named it. Then compile.

vs49688
Light Poster
48 posts since Dec 2007
Reputation Points: 10
Solved Threads: 1
 

If you are working with Dev C++ Compiler,then simply Go to The Project Options & Browse for the Icon You want have for your C++ Console app....

msk88
Newbie Poster
17 posts since Feb 2008
Reputation Points: 10
Solved Threads: 2
 

Hate to admit it, but you're right. you can only use msk88's suggestion for Dev projects. :(

CodeBoy101
Junior Poster in Training
71 posts since Dec 2007
Reputation Points: 8
Solved Threads: 0
 

I am using code blocks, is it possible to change the icon in that for the exe?

Thanks, Regards X

OmniX
Practically a Master Poster
656 posts since Dec 2007
Reputation Points: 31
Solved Threads: 10
 

Wait... this is marked as solved?

Console programs can have any and all of the same resources as Window GUI programs, but they typically aren't built with them. On Windows, EXE, DLL, OBJ, and a few other files are all the PE32 file format.

For MinGW users in general, you need to create an RC file, like:

MAINICON ICON "foo.ico"

Then usewindres to compile it to a linkable object file:
C:\prog\foo> windres fooicon.rc fooicon.o

When you compile, just link it into the exe as usual: C:\prog\foo> g++ foo.cpp fooicon.o

ForCode::Blocks users, you only need to go so far as to create the RC file and add it to your project. The IDE can handle compiling it correctly.

Have fun!

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

Sorry about the pain but possible step by step for code::blocks plz?

I tried making an empty file and naming it *.rc and then add files but everything time i click does nothing.

OmniX
Practically a Master Poster
656 posts since Dec 2007
Reputation Points: 31
Solved Threads: 10
 

Empty files will never do anything except exist. ("Existing is basically all I do!" --Fry)

It also sounds like there is something misconfigured with your Code::Blocks IDE. Have you been able to compile other projects? Are you using a compiler other than MinGW?

If no to one or both of those:From the main menu select Settings|Compiler and debugger...
Make sure your Selected compiler is the compiler you plan to use.
Mine is the "GNU GCC Compiler" option.
Click the Toolchain executables tab.
Make sure the Compiler's installation directory is correct.
I keep my MinGW in C:\Program Files\MinGW , but most users will have it in the default installation path: C:\MinGW
If you are using another compiler, for example, CodeGear Turbo C++ Explorer, make sure you've got its installation directory listed C:\Program Files\Borland\BDS\4.0
In theProgram Files tab, make sure each item correctly identifies the executable. Mine uses all the default stuff for GCC:

C Compiler:			mingw32-gcc.exe
C++ Compiler:			mingw32-g++.exe
Linker for dynamic libs:	mingw32-g++.exe
Linker for static libs:		ar.exe
Debugger:			gdb.exe
Resource compiler:		windres.exe
Make program:			mingw32-make.exe

Again, if you are using something different, make sure you've got the correct executables. For TC++Explorer you'll want to make sure you've got something like:

C++ Compiler:			bcc32.exe
Linker for static libs:		ilink32.exe
Resource compiler:		brcc32.exe
Make program:			make.exe

Et cetera.
If you aren't using the GCC you'll also want to make sure you've got the proper global variables set up. See here for more .
Test compile something simple to make sure you've got it working.

Now, to add a main icon resource to your program, a quick walk-through:Create a New Project... and choose a Console application. This will give you a default main.cpp that simply prints "Hello world!".
Find or create an icon to represent your application. Add it to your project. Mine is named spiffomatic.ico .
Create a new file in your project named resources.rc . It doesn't have to be named "resources", but that's what I chose.
Add the following line to resources.rc :

MAINICON  ICON  "spiffomatic.ico"

Notice how I gave the filename of the icon file I added to the project? Save all changes.
At this point the Projects Management pane on the left should look something like this:

[-] Workspace
    [-] Spiffomatic
        [-] Sources
         |   |_ main.cpp
        [-] Resources
         |   |_ resources.rc
        [-] Others
             |_ spiffomatic.ico
HitCtrl-F9 (or Build|Build from the main menu).

You should now be able to navigate to your application's EXE using Windows Explorer and see it represented with the icon you selected for it. If compilation fails, make sure you have all the compiler options correct and try again.

Another path would be to just download Resource Hacker and use it to modify your EXE directly.

Good luck!

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

Very sexy work, one of the most helpful and stepful posts I have seen.

Thankyou very much Duoas!!!

OmniX
Practically a Master Poster
656 posts since Dec 2007
Reputation Points: 31
Solved Threads: 10
 

i'm using dev c++..
what library file i have to download?

kiwihaha
Light Poster
34 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 
i'm using dev c++.. what library file i have to download?

To do what?

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 
To do what?

to recognize the code "MAINICON ICON"

sorry sorry
forget change the extendtion from .cpp to .rc

can already... thx

kiwihaha
Light Poster
34 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You