Thread: Quick question about winAPI resource files & icons

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    30

    Quick question about winAPI resource files & icons

    Tutorial: Using Resources

    The above tutorial has some very nice explanations and I feel pretty good with the content it taught me; however, one thing I'm not too clear on is:

    1) What are these integers representing? E.g:

    Code:
    #define IDI_ICON 101
    What does the int 101 stand for?

    2) What actually goes within a resource file? Like in the tutorial, it's example was: resource.h - however, it never actually seemed to talk about that file itself and what actually gets put in it.

    Thanks,
    Justin

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    "...What does the int 101 stand for?..."

    Resources are represented by integers, and you define an integer with an easily readable value

    Code:
    //resource file *rc
    MY_APPLICATION_ICON ICON "my_application_icon.ico"
    
    //definitions file
    #define MY_APPLICATION_ICON 101
    
    //whatever where you need in application code
    LoadIcon(hInstance, MAKEINTRESOURCE(MY_APPLICATION_ICON));
    Is easier and more understandable to use MY_APPLICATION_ICON as reference to my application icon that a 101 value. That value is arbitrary (it can be 4567 as well if you want), just do not repeat it by identifing resources.

    The trick I do is (i.ex.): knowing that I usually won't load more that 100 objects of each resource type (BITMAP, ICON, etc..), just use the range from 100-199 for icons, 200-299 to bitmaps, and so on.

    Hope that helps
    Niara
    Last edited by Niara; 01-04-2013 at 12:27 PM.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    "...What actually goes within a resource file?..."

    Well, on the resource files goes the resources

    Heres a sample from both files:

    Code:
    //definitions.h
    #define ARBITRARY_IMAGE_ID 100
    #define QUIT_MENU_BUTTON 200
    Code:
    //resource.rc
    #include <windows.h>
    #include "definitions.h"
    
    ARBITRARY_IMAGE_ID BITMAP "image.bmp"
    
    //can mix with menu templates
    menu MENU
    BEGIN
        POPUP "&File"
        BEGIN
            MENUITEM "&Quit", QUIT_MENU_BUTTON
        END
    END
    Niara
    Last edited by Niara; 01-04-2013 at 12:35 PM.

  4. #4
    Registered User
    Join Date
    Oct 2012
    Posts
    30
    Thanks! I really appreciate the replies, and definitely understand it a bit more. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick question on reading files in C
    By TaiL in forum C Programming
    Replies: 12
    Last Post: 10-05-2008, 09:48 PM
  2. Quick question, print to two files
    By vutek0328 in forum Tech Board
    Replies: 4
    Last Post: 07-18-2007, 03:55 PM
  3. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 07:18 AM
  4. Resource Files in WinAPI ?!?! HELP!!!!!
    By syn2oo1 in forum Windows Programming
    Replies: 0
    Last Post: 11-26-2001, 03:47 AM
  5. quick question about header files
    By Kirstin in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2001, 11:21 AM