Thread: resources

  1. #1
    Registered User Gnoober's Avatar
    Join Date
    Oct 2002
    Posts
    40

    resources

    Does anyone know where I could find out how to link resources to my program (in windows). I can create the resource file but I'm not sure how to get it to link to my program. I have created an icon and created the resource file but how do I make the icon show up for my program instead of that default white window? Any help is appreciated! Thanks
    Last edited by Gnoober; 10-16-2002 at 02:40 PM.
    - Grady (:

  2. #2
    julie lexx... btq's Avatar
    Join Date
    Jun 2002
    Posts
    161
    dunno what you're using, in vc it's just to add...
    if you link with 'link.exe' it's just to..uhm...link with it..
    then check out the hicon field of WNDCLASSEX and LoadResource() and you're all set..

    /btq
    ...viewlexx - julie lexx

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    in vc it's just to add...
    if you link with 'link.exe' it's just to..uhm...link with it..
    then check out the hicon field of WNDCLASSEX and LoadResource() and you're all set..
    *deciphered version*
    Well, you first of all include the header with the stuff. Then, you go to your initialization code, and where you create and fill in a WNDCLASSEX struct, you fill the hIcon member variable using the return value of LoadResource().

    P.S. Personally, I think LoadIcon() would be more practical for this purpose...
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Registered User Gnoober's Avatar
    Join Date
    Oct 2002
    Posts
    40
    I'm not sure if I understand...
    Heres what I get out of that:

    I must create a WMDCLASSEX object and then use

    Code:
    object.hIcon = LoadIcon();
    Could someone explain it more for a "junior member" and not a "Codetagerator" ? Thanks!
    - Grady (:

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    hiya,

    those are win32 api's that you use, it handles all the stuffs for you. ie, it handles your icons so when you compile your app, it automatically includes/appends your icon into your exe, that's it.

    so when you call LoadIcon(...), it gets your icon on your resource file and includes it in your program,

  6. #6
    Registered User Gnoober's Avatar
    Join Date
    Oct 2002
    Posts
    40
    So in the main, I should just type

    LoadIcon(nameOfResource);

    It seems too easy Maybe I'm missing something
    - Grady (:

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by Gnoober
    So in the main, I should just type

    LoadIcon(nameOfResource);

    It seems too easy Maybe I'm missing something
    Unless your resource name is in quotes, you must use the macro MAKEINTRESOURCE( ) for the conversion.

    Code:
    LoadIcon( GetModuleHandle( NULL ), MAKEINTRESOURCE( IDC_ICON ) );
    The first parameter is the handle to the application instance.

  8. #8
    Registered User Gnoober's Avatar
    Join Date
    Oct 2002
    Posts
    40
    Ok... It isn't working

    here's my code:
    Code:
    LoadIcon( GetModuleHandle( NULL ), MAKEINTRESOURCE( "icon.rc") );
    I have the resource file created and it compiles just fine but the icon doesn't show up in place of the default window icon. What's wrong?
    - Grady (:

  9. #9
    Registered User Gnoober's Avatar
    Join Date
    Oct 2002
    Posts
    40
    Never Mind, I got it to work. I made a stupid mistake and didn't add the resource file to my project . Thanks so much for all the help!
    - Grady (:

  10. #10
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    hi, it seems so easy because well, that's what API's are for, make life easier,

  11. #11
    Registered User
    Join Date
    Jan 2003
    Posts
    3

    HELLLLLPPPP I can't get it...whats wrong

    Originally posted by Gnoober
    Ok... It isn't working

    here's my code:
    Code:
    LoadIcon( GetModuleHandle( NULL ), MAKEINTRESOURCE( "icon.rc") );
    I have the resource file created and it compiles just fine but the icon doesn't show up in place of the default window icon. What's wrong?
    I did what this says...but I still get errors...bigtime...

  12. #12
    Registered User Caze's Avatar
    Join Date
    Nov 2002
    Posts
    18
    You have to chance your code a bit. For the first you can not use MAKEINTRESOURCE that way. If you are going use it, you have to first create a header file where you define the icon, like this:
    Code:
    main.h
    
    #define ICON_NAME 1
    Then you create a resource file like this:
    Code:
    main.rc
    
    #include "main.h"
    ICON_NAME ICON name_of_file.ico
    And here is the modified cpp file:
    Code:
    main.cpp
    
    #include "main.h"
    wincl.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(ICON_NAME));
    wincl.hIconSm = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(ICON_NAME));
    That should get it to work.

    Or you could simply leave out the header file and load the icon like this:
    Code:
    wincl.hIcon = LoadIcon (GetModuleHandle(NULL), "ICON_NAME");
    wincl.hIconSm = LoadIcon (GetModuleHandle(NULL), "ICON_NAME");
    Last edited by Caze; 01-07-2003 at 11:04 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Resources in Dev C++
    By JJFMJR in forum Windows Programming
    Replies: 7
    Last Post: 08-27-2007, 05:14 AM
  2. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  3. Getting resources from another program.
    By Queatrix in forum C++ Programming
    Replies: 3
    Last Post: 02-11-2006, 09:00 PM
  4. Storing resources into a single file
    By LuckY in forum Game Programming
    Replies: 20
    Last Post: 08-14-2004, 11:28 PM
  5. Adding resources
    By nima_ranjbar in forum Windows Programming
    Replies: 0
    Last Post: 04-14-2002, 11:36 PM