How do I add an icon to a C program?

This is a discussion on How do I add an icon to a C program? within the Windows Programming forums, part of the Platform Specific Boards category; I am using MS Visual C++ 6.0, I have an icon that I made in Visual C++. Is there a ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    98

    Question How do I add an icon to a C program?

    I am using MS Visual C++ 6.0,
    I have an icon that I made in Visual C++. Is there a way that I can compile my program so that the final .exe file has the icon I made, not the usual icon?
    Thanks

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    The application should be built automatically with the icon with the lowest id that's part of the executable's resources.

    If the application is non-console then you'll have to take extra steps if you want the window icon to be the one you want. For example, in winapi you would either register the window class with the icon you want or send a WM_SETICON message.

    This is a windows specific question so I'm moving it there.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,266
    So, to facilitate all that, you first need a resource file, which can be as simple as:-
    Code:
    #include "resource.h"
    
    IDI_ICON ICON "icon.ico"
    Save that with an .rc extension and add it to your project's Resource Files folder.

    You'll also need a resource.h to include, which can say:-
    Code:
    #define IDI_ICON	100
    Note the second line. There's a problem with Microsoft's resource compiler (which bizarrely still hasn't been fixed after several service packs) that makes it fail to recognize the end of file condition unless there's an empty line at the end. I don't know whether this has been fixed in later releases.

    That should get you an icon called icon.ico from your project's directory into your program, then you simply have to do as Ken suggested to use it the usual way.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    98
    Thanks man. You rock!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  2. Add a dialog box to a tab
    By axr0284 in forum Windows Programming
    Replies: 0
    Last Post: 01-10-2005, 08:38 AM
  3. Replies: 3
    Last Post: 01-14-2003, 10:34 PM
  4. Replies: 2
    Last Post: 05-10-2002, 05:16 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21