Adding a custom Icon

This is a discussion on Adding a custom Icon within the Windows Programming forums, part of the Platform Specific Boards category; How od I add my own custom .ICO to the titlebar? here is the code I use for that part... ...

  1. #1
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77

    Adding a custom Icon

    How od I add my own custom .ICO to the titlebar?

    here is the code I use for that part...


    Code:
    winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);

    ~Trooper
    Your mom is like a struct, she has no class

    How many C programmers does it take to screw in a light bulb? One to do it, 99 to tell him how to do it faster.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544

  3. #3
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77
    so I would do


    Code:
    #define IDI_MYICON ICON "myicon.ico"
    
    winclass.hIcon = LoadIcon(NULL, IDI_IDI_MYICON);
    ??

    I tried that and didn't work.



    ~Trooper
    Your mom is like a struct, she has no class

    How many C programmers does it take to screw in a light bulb? One to do it, 99 to tell him how to do it faster.

  4. #4
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Use LoadIcon() if you're loading an icon resource. You should make an icon resource first.

    If you're loading the icon from a .ico file, use the LoadImage() function:

    Code:
     LoadImage( GetModuleHandle(0), "myicon.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);

  5. #5
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Easier IMO :

    Code:
    //*.rc file
    #include "rs.h" //header containing definition of IDI_MYICON
    IDI_MYICON ICON "c:\\somepath\\myiconname.ico"
    And:
    Code:
    //in .cpp
    winclass.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_MYICON));
    You can also use a string to refer to an icon in your rc file (i think) but I have always used this...its basically the same for a cursor except you would use CURSOR where ICON is and fill in the corresponding line:

    Code:
    winclass.hCursor		= LoadCursor(hinstance, MAKEINTRESOURCE(IDC_MYCURSOR));
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 08-04-2008, 05:34 PM
  2. SVN Import Causes Crash
    By Tonto in forum Tech Board
    Replies: 6
    Last Post: 11-01-2006, 02:44 PM
  3. Custom Icon for DLL
    By Delf in forum Windows Programming
    Replies: 5
    Last Post: 06-10-2005, 08:36 AM
  4. Adding an Icon
    By osal in forum Windows Programming
    Replies: 4
    Last Post: 06-28-2004, 11:43 AM
  5. adding icon to a file that ISN'T win32
    By jverkoey in forum C++ Programming
    Replies: 2
    Last Post: 09-07-2003, 10:40 PM

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