This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to embed icon for the executable


Michael Foo wrote:

> I am using Cygwin on Windows ME. After "gcc -o foo.exe foo.c", it create
> a default windows icon for foo.exe. However, I wish to replace the icon
> with another icon (.ico) which I downloaded from the internet. Any clue
> or help how to add this .ico file to my executable?

I've never done this with cygwin but the basic process is:

    1. write an .rc file (resource script)
    2. compile the .rc and the .ico into a .res
    3. link the .res into your .exe

You can find documentation for .rc files in the online MSDN library

    http://msdn.microsoft.com/library/en-us/tools/rc_6cs3.asp

and you want something like:

    LANGUAGE 0, 0
    100     ICON    filename.ico

By default, the shell uses the first icon it finds; traditionally, the
lowest resource number used is ID 100. If you need to access this from
your program, you usually create a file 'resource.h' which #defines
IDI_MAINICON 100 or similar and then #include this in the resource script.
Rather than 0,0 for the language ID (LANG_NEUTRAL, SUBLANG_NEUTRAL) you
can #include <windows.h> and use

    #include <windows.h>
    LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
    100     ICON    filename.ico

You then compile this to a .res using a resource compiler; I think there's
one in binutils called 'windres' or similar which you should have already
installed. Alternatively, you can download the Microsoft Platform SDK

    http://www.microsoft.com/msdownload/platformsdk/sdkupdate/

and use Microsoft's own, rc.exe.

Then, finger's crossed, you just add the .res to the compile / link line
and the linker takes care of the rest.

Good luck,
Rup.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]