Thread: How do I add an icon to a C program?

  1. #1
    Registered User
    Join Date
    Sep 2006

    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?

  2. #2
    Join Date
    Jan 2002
    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
    Newport, South Wales, UK
    So, to facilitate all that, you first need a resource file, which can be as simple as:-
    #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:-
    #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
    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, 12: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, 04:16 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM