Author Topic: Program Icon  (Read 10745 times)

Offline Acki

  • Multiple posting newcomer
  • *
  • Posts: 100
Program Icon
« on: January 30, 2006, 06:20:09 pm »
Hi,
I just changed to CB and it seems to be grat !!! :)
Previously I used DevCpp...
In Dev I can define the program icon in the programs settings for GUI apps!
In CB I didn't find this setting... :(

Is there a way to set the program's icon in C::B ???
Or do I have to use a recourse editor/hacker to add the icon after compiling !?!?!

thx, Acki

sethjackson

  • Guest
Re: Program Icon
« Reply #1 on: January 30, 2006, 06:42:47 pm »
Hi,
I just changed to CB and it seems to be grat !!! :)
Previously I used DevCpp...
In Dev I can define the program icon in the programs settings for GUI apps!
In CB I didn't find this setting... :(

Is there a way to set the program's icon in C::B ???
Or do I have to use a recourse editor/hacker to add the icon after compiling !?!?!

thx, Acki


No I don't think there is any setting like that.....

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: Program Icon
« Reply #2 on: January 30, 2006, 08:33:27 pm »
The simplest way for you to add an Explorer and shortcut icon for your program would be in a resource file.

- Create a new file with a .rc extension
- To that file, add a line like "MyIconName ICON myiconfile.ico"
- If you add the file to your project, Code::Blocks should compile correctly for you

This icon will be seen by Explorer as the first icon in your .exe and it will be used whenever the program file or a shortcut to it is displayed. Making the same icon show up in the upper left corner of your program window and in the taskbar is somewhat more complicated.

Hope that helps,
JohnE / TDM
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Offline anarxia

  • Single posting newcomer
  • *
  • Posts: 7
Re: Program Icon
« Reply #3 on: January 31, 2006, 09:12:23 am »
The way to set application icon is dependend on the toolkit used (which is obviously what you meant).
Here's a short example for Win32 which should work for most cases:

In your rc file: (2 is arbitrary)
Code: [Select]
2 ICON "myicon.ico"

And somewhere in your window create function (notice the 2 again):
Code: [Select]
HICON hICon;

hICon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(2));

SetClassLong(hWnd,            // window handle
                  GCL_HICON,     // changes icon
                  (LONG) hIcon); // The new icon

PostMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) hIcon);

Offline Acki

  • Multiple posting newcomer
  • *
  • Posts: 100
Re: Program Icon
« Reply #4 on: February 01, 2006, 01:00:18 am »
Thanks !!! :)
I used TDragon's solution and it works !!!

eks

  • Guest
Re: Program Icon
« Reply #5 on: April 22, 2006, 04:38:52 pm »
Just look into a .rc file generated by Devcpp (when you add an icon), you should see something like this :
Code: [Select]
A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "MyIcon.ico"Copy-paste this line into a .rc file of your project (create one if needed) and change the filename.

It works fine with gcc, I did not try with other compilers.

Offline yckx

  • Multiple posting newcomer
  • *
  • Posts: 10
    • http://
Re: Program Icon
« Reply #6 on: August 31, 2006, 11:55:35 pm »
Sorry to dig up an old thread, but I was searching for an answer to a similar problem, and this seems like as good a place as any to document what I found, so others may benefit.  I had several ICON definitions in my RC file, and I couldn't figure out how to tell Code::Blocks which one to use as the icon for Windows Explorer.  This was my code:
Code: [Select]
ID_ICON_KRAT_16 ICON "resource\\krat_16.ico"
ID_ICON_KRAT_32 ICON "resource\\krat_32.ico"
ID_ICON_KRAT_48 ICON "resource\\krat_48.ico"
I tried re-ordering the lines, and sought for some option in Code::Blocks to let me choose which icon would be used.  Turns out I was looking in the wrong place. In my resdefs.hpp file I had this:
Code: [Select]
#define ID_ICON_KRAT_16     1000
#define ID_ICON_KRAT_32     1001
#define ID_ICON_KRAT_48     1002
Well, I finally tried changing the defines, and learned that the resulting EXE uses the icon with the lowest-numbered ID for its icon in Windows Explorer.  I don't know if this is standard Windows behavior or just how C::B/mingw defaults, but now that I've figured it out, I'm a happy man.  And maybe somebody else can benefit from my extraordinarily inefficient use of time ;)

Offline troels

  • Multiple posting newcomer
  • *
  • Posts: 71
Re: Program Icon
« Reply #7 on: September 01, 2006, 08:48:14 am »
Code: [Select]
ID_ICON_KRAT_16 ICON "resource\\krat_16.ico"
ID_ICON_KRAT_32 ICON "resource\\krat_32.ico"
ID_ICON_KRAT_48 ICON "resource\\krat_48.ico"

The idea is to bundle icons of different sizes into just one single 'compound' icon.
Windows will then pick one out of this 'compound' icon, the one that matches the best.