943,919 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 18111
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Apr 27th, 2008
0

How to change icon of C++ console app

Expand Post »
How do I change the icon of the exe. in console mode? (as part of the exe itself)
Similar Threads
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
CodeBoy101 is offline Offline
71 posts
since Dec 2007
Apr 27th, 2008
-1

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

You don't -- console programs do not have resources so its not possible to change an icon that doesn't exist.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Apr 28th, 2008
0

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

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 1
Light Poster
vs49688 is offline Offline
48 posts
since Dec 2007
Apr 28th, 2008
0

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

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.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
msk88 is offline Offline
17 posts
since Feb 2008
May 7th, 2008
0

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

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.
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
CodeBoy101 is offline Offline
71 posts
since Dec 2007
Aug 23rd, 2008
0

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

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

Thanks, Regards X
Reputation Points: 31
Solved Threads: 10
Practically a Master Poster
OmniX is offline Offline
652 posts
since Dec 2007
Aug 23rd, 2008
1

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

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:
C++ Syntax (Toggle Plain Text)
  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!
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007
Aug 24th, 2008
0

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

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.
Reputation Points: 31
Solved Threads: 10
Practically a Master Poster
OmniX is offline Offline
652 posts
since Dec 2007
Aug 24th, 2008
4

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

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:
    C++ Syntax (Toggle Plain Text)
    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:
    C++ Syntax (Toggle Plain Text)
    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:
    C++ Syntax (Toggle Plain Text)
    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:
    C++ Syntax (Toggle Plain Text)
    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!
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007
Aug 25th, 2008
0

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

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

Thankyou very much Duoas!!!
Reputation Points: 31
Solved Threads: 10
Practically a Master Poster
OmniX is offline Offline
652 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Questions About C++.NET - I Need Help Please
Next Thread in C++ Forum Timeline: Visual C++ include directories help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC