Icons

This is not really a question about C++ source code writing, but some of you who use Microsoft Visual C++ (more specifically, version 6.0, but it may not matter) might be able to help me. When you finish a program and build it, the application file has no icon. It just has that default icon that looks like a little box that they automatically give it. I havn't been able to figure out how to assign my own icon to a program. I know you can make your own icons with the Visual C++ program, but how do you get it to actually use your icon? Is it possible to do it with the Visual C++ program, or does some other software need to be purchased? I'd appreciate some help.

Simon H.

Comments

  • : This is not really a question about C++ source code writing, but some of you who use Microsoft Visual C++ (more specifically, version 6.0, but it may not matter) might be able to help me. When you finish a program and build it, the application file has no icon. It just has that default icon that looks like a little box that they automatically give it. I havn't been able to figure out how to assign my own icon to a program. I know you can make your own icons with the Visual C++ program, but how do you get it to actually use your icon? Is it possible to do it with the Visual C++ program, or does some other software need to be purchased? I'd appreciate some help.
    :
    : Simon H.
    :

    No, VC++ does it all. Just add/edit your icon resource and make sure to load it manually if your not using an app-wizard generated project.
  • You want specific code? Well here we go:

    After you create an icon (you should create a 32x32 and a 16x16 in the SAME resource) and have it in the app....

    There is a structure you use in Win32 (if that's what you're doing...) called WNDCLASS (I like it better than WNDCLASSEX). There is an m_hIcon i believe. Simply say LoadIcon(HINSTANCE, LPCTSTR), the second parameter is the resource string. If you save the resouce with an integer ID then use the MAKEINTRESOURCE() macro to convert.

    ex.

    //Not sure if the member is exactly m_hIcon...

    WNDCLASS wc;

    wc.m_hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));

    RegisterClass(...);

    Okay, so there you have it. All you do is register it with the windows class, then call RegisterClass. Easy enough. Just remember to have both 32x32 and 16x16 in one resource (it's easier anyway).

    What about dialog boxes? You don't really register those. So, what I do is use SetClassLong(). If you can get the HWND in the WinMain function, do it there. I Believe it is prototyped as:

    SetClassLong(HWND, UINT, LONG);

    Set the HWND, then enter a UINT constant to tell the system you are setting the icon (look up the values at MSDN), then call LoadIcon(). YOU MUST TYPECAST the return value to a LONG.

    (LONG)LoadIcon(HINSTANCE, LPCTSTR);

    Otherwise, if it is MFC done with AppWizard, just replace their IDR_MAINFRAME icon with your own (with the same name) and run it.

  • [b][red]This message was edited by shbomb at 2002-10-30 10:23:47[/red][/b][hr]
    Well I should have been more specific. I'm doing Win32 Console programming (for which there is no wizard of any sort as far as I know) at this point in time (you know, the MS-DOS window). So even when I load in the icon as a resource it doesn't assign it tho the released program file, and I'm not really an expert programmer, so someone out there would have to post an example of an enire source code (with whatever headers or anything else I'd have to inculde) and explain where every file has to be etc.

    Or maybe it's not even that complicated. I don't think I was specific enough at first, sorry. All I want to do is have an Win32 Console (black screen with white text) that has an icon that I made instead of that default one that looks like a box, and I can't figure out how to tell the compiler to use my icon when it compiles, and just adding it to the project doesn't work.

    SH


  • Do this:

    1. Copy the .ICO you want into your project folder.
    2. In your project, select File/New
    3. From the "New" dialog box, select "Resource Script" from the "File" tab, give it a name, anything with .rc would do such as "main.rc".
    4. Goto Resource View, right click "XXX resources" then select "Properties". uncheck "Enable MFC Features".
    5. Right click "XXX Resources" again, select import and browse to the .ICO file you want.
    6. That's it, rebuild and you should have your icon.


    : [b][red]This message was edited by shbomb at 2002-10-30 10:23:47[/red][/b][hr]
    : Well I should have been more specific. I'm doing Win32 Console programming (for which there is no wizard of any sort as far as I know) at this point in time (you know, the MS-DOS window). So even when I load in the icon as a resource it doesn't assign it tho the released program file, and I'm not really an expert programmer, so someone out there would have to post an example of an enire source code (with whatever headers or anything else I'd have to inculde) and explain where every file has to be etc.
    :
    : Or maybe it's not even that complicated. I don't think I was specific enough at first, sorry. All I want to do is have an Win32 Console (black screen with white text) that has an icon that I made instead of that default one that looks like a box, and I can't figure out how to tell the compiler to use my icon when it compiles, and just adding it to the project doesn't work.
    :
    : SH
    :
    :
    :

  • It worked, thanks a whole bunch.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories