How to change icon of C++ console app

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2007
Posts: 65
Reputation: CodeBoy101 is an unknown quantity at this point 
Solved Threads: 0
CodeBoy101's Avatar
CodeBoy101 CodeBoy101 is offline Offline
Junior Poster in Training

How to change icon of C++ console app

 
0
  #1
Apr 27th, 2008
How do I change the icon of the exe. in console mode? (as part of the exe itself)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,462
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1476
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to change icon of C++ console app

 
-1
  #2
Apr 27th, 2008
You don't -- console programs do not have resources so its not possible to change an icon that doesn't exist.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 42
Reputation: vs49688 is an unknown quantity at this point 
Solved Threads: 1
vs49688 vs49688 is offline Offline
Light Poster

Re: How to change icon of C++ console app

 
0
  #3
Apr 28th, 2008
  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 17
Reputation: msk88 is an unknown quantity at this point 
Solved Threads: 2
msk88 msk88 is offline Offline
Newbie Poster

Re: How to change icon of C++ console app

 
0
  #4
Apr 28th, 2008
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....
Last edited by msk88; Apr 28th, 2008 at 12:30 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 65
Reputation: CodeBoy101 is an unknown quantity at this point 
Solved Threads: 0
CodeBoy101's Avatar
CodeBoy101 CodeBoy101 is offline Offline
Junior Poster in Training

Re: How to change icon of C++ console app

 
0
  #5
May 7th, 2008
Hate to admit it, but you're right. you can only use msk88's suggestion for Dev projects.
Last edited by CodeBoy101; May 7th, 2008 at 1:24 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 609
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: How to change icon of C++ console app

 
0
  #6
Aug 23rd, 2008
I am using code blocks, is it possible to change the icon in that for the exe?

Thanks, Regards X
"You never stop learning." - OmniX
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to change icon of C++ console app

 
0
  #7
Aug 23rd, 2008
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:
  1. MAINICON ICON "foo.ico"
Then use windres 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

For Code::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!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 609
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: How to change icon of C++ console app

 
0
  #8
Aug 24th, 2008
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.
"You never stop learning." - OmniX
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to change icon of C++ console app

 
3
  #9
Aug 24th, 2008
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:
  1. From the main menu select Settings|Compiler and debugger...
  2. Make sure your Selected compiler is the compiler you plan to use.
    Mine is the "GNU GCC Compiler" option.
  3. Click the Toolchain executables tab.
  4. 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
  5. In the Program Files tab, make sure each item correctly identifies the executable. Mine uses all the default stuff for GCC:
    1. C Compiler: mingw32-gcc.exe
    2. C++ Compiler: mingw32-g++.exe
    3. Linker for dynamic libs: mingw32-g++.exe
    4. Linker for static libs: ar.exe
    5. Debugger: gdb.exe
    6. Resource compiler: windres.exe
    7. 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:
    1. C++ Compiler: bcc32.exe
    2. Linker for static libs: ilink32.exe
    3. Resource compiler: brcc32.exe
    4. 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.
  6. 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:
  1. Create a New Project... and choose a Console application. This will give you a default main.cpp that simply prints "Hello world!".
  2. Find or create an icon to represent your application. Add it to your project. Mine is named spiffomatic.ico.
  3. Create a new file in your project named resources.rc. It doesn't have to be named "resources", but that's what I chose.
  4. Add the following line to resources.rc:
    1. MAINICON ICON "spiffomatic.ico"
    Notice how I gave the filename of the icon file I added to the project? Save all changes.
  5. At this point the Projects Management pane on the left should look something like this:
    1. [-] Workspace
    2. [-] Spiffomatic
    3. [-] Sources
    4. | |_ main.cpp
    5. [-] Resources
    6. | |_ resources.rc
    7. [-] Others
    8. |_ spiffomatic.ico
  6. Hit Ctrl-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!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 609
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: How to change icon of C++ console app

 
0
  #10
Aug 25th, 2008
Very sexy work, one of the most helpful and stepful posts I have seen.

Thankyou very much Duoas!!!
"You never stop learning." - OmniX
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC