| | |
How to change icon of C++ console app
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Dec 2007
Posts: 42
Reputation:
Solved Threads: 1
C++ Syntax (Toggle Plain Text)
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.
I am using code blocks, is it possible to change the icon in that for the exe?
Thanks, Regards X
Thanks, Regards X
"You never stop learning." - OmniX
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:
Then use windres to compile it to a linkable object file:
When you compile, just link it into the exe as usual:
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!
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)
MAINICON ICON "foo.ico"
C:\prog\foo> windres fooicon.rc fooicon.oWhen you compile, just link it into the exe as usual:
C:\prog\foo> g++ foo.cpp fooicon.oFor 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!
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.
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
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:
Now, to add a main icon resource to your program, a quick walk-through:
Another path would be to just download Resource Hacker and use it to modify your EXE directly.
Good luck!
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 inC:\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 listedC:\Program Files\Borland\BDS\4.0 - In the Program Files tab, make sure each item correctly identifies the executable. Mine uses all the default stuff for GCC:
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)- 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
Et cetera.C++ Syntax (Toggle Plain Text)- C++ Compiler: bcc32.exe
- Linker for static libs: ilink32.exe
- Resource compiler: brcc32.exe
- Make program: make.exe
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.cppthat 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:
Notice how I gave the filename of the icon file I added to the project? Save all changes.C++ Syntax (Toggle Plain Text)- MAINICON ICON "spiffomatic.ico"
- At this point the Projects Management pane on the left should look something like this:
C++ Syntax (Toggle Plain Text)- [-] Workspace
- [-] Spiffomatic
- [-] Sources
- | |_ main.cpp
- [-] Resources
- | |_ resources.rc
- [-] Others
- |_ spiffomatic.ico
- Hit Ctrl-F9 (or Build|Build from the main menu).
Another path would be to just download Resource Hacker and use it to modify your EXE directly.
Good luck!
![]() |
Similar Threads
- Server Busy Virus - Hijack log (Viruses, Spyware and other Nasties)
- blank pop-ups (Viruses, Spyware and other Nasties)
- Help! HJT log can't access internet anymore (Viruses, Spyware and other Nasties)
- spyware nasty (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Questions About C++.NET - I Need Help Please
- Next Thread: window creating w/ textbackground help
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






