Thread: What does this mean!?!?!

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    4

    What does this mean!?!?!

    #define IDD_DIALOG1 101
    #define IDD_RMS 101
    #define IDI_UP 105
    #define IDI_DOWN 106

    What are the numbers for? this is in a resource.h file

    Please help me....

  2. #2
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Those are reference numbers, probably for a resource file.

    It just defines a constant that can be used in the resource file, and you'll know what it is for later use in a command switch and stuff

    so I could define something like this

    #define ID_MENU_ITEM 100

    and in the resourece file I can set a menu up and use ID_MENU_ITEM for a reference.

    the in my program I coud

    Code:
    switch(WM_COMMAND) {
    
        case ID_MENU_ITEM:  blahblah break;
    
    }
    Last edited by Vicious; 08-29-2004 at 04:40 PM.

  3. #3
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    when you #define something, the occurrances of the defined constant will be inlined in the code at compile time.

    ex. code:
    #define FOO 10
    ....
    int x = FOO * 4;

    meanwhile, at compile time... the compiler sees

    int x = 10 * 4;

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Specifically, as vicious said, that looks like a resource file. You'll learn all about that if you do any WinAPI programming. They're defining the necessary constants for use in a pop-up menu.

  5. #5
    I'm less than sure.... abyssphobia's Avatar
    Join Date
    Aug 2004
    Posts
    112
    Well I know that you can use
    Code:
      #define abyss 12.43
    , but its much better to use const
    example
    Code:
     const double abyss = 12.43; //this contains a double value  that never change.
    but you can also make a constant volatile, that amazing about programming
    that makes the constant change in ways especified by the program,

    its the same game,Im glad if this helps!

    ------------------------abyssphobia--------------------------
    Have I crossed the line?

  6. #6
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Well the most noticable difference in #define and const variables is that #define is preprocessor.

    But I couldnt go into detail and explain why/if one is better than the other.

  7. #7
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    One use I see for #define that const does not support is allowing you to specify, via preprocessors as Vicious mentioned, which sections of your code you want compiled based on various things such as debugging and the platform you are on at the moment.

    As far as I can tell the difference is that #define names are replaced with values at compile time whereas const variables are in existance during runtime like normal variables but cannot be modified. I may be off in this assumption but I think it is probably correct.

  8. #8
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Another thing is you can make macros with #define

    [Example]
    Code:
    #define NIBBLE  (Value & 0xF0) >> 4

  9. #9
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    This is wayyyy off topic. The original question was in regard to resource.h, which is probably a MSVC-generated resource header.

    >>You'll learn all about that if you do any WinAPI programming.
    Not if you're using MSVC, I've used the resource editor for about a year now, and to my shame I still have no idea how the darned things work.

    MattNowaczewski:
    If you're using MSVC, all you really need to know is:
    -add the .rc file to your project
    -include the resource.h in your main.cpp
    -the #define's are usually for use in your Windows procedure. The #define's refer to specific resources (usually controls in a dialog box such as buttons, edit boxes, etc.) that are in the .rc file. If they're controls in a dialog box, they're for use in the WM_COMMAND message as someone has mentioned above.

    **EDIT**
    The IDD_ means that it's an "ID for a Dialog box", while IDI_ means "ID for an icon". Another you might find is IDC_, for "ID of a dialog control". Note that this isn't ALWAYS the case, since you can call them anything really, but that's the general MS convention for it.

    Hope this helps!

    **PS. People, I'm sure there's tons of #define vs. const/inline threads out there. Do a board search or something instead of posting it all here.
    Last edited by Hunter2; 08-30-2004 at 05:20 PM.
    Just Google It. √

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

  10. #10
    Registered User
    Join Date
    Jun 2004
    Posts
    201
    One advantage of using #define over const is in embedded systems with slow processors. A const could require a memory fetch each time it is accessed while a define will be in the processor immediately, because the exact asm is emitted for it.

Popular pages Recent additions subscribe to a feed