#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....
Printable View
#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....
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 :D
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;
}
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;
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.
Well I know that you can use
, but its much better to use constCode:#define abyss 12.43
example
but you can also make a constant volatile, that amazing about programmingCode:const double abyss = 12.43; //this contains a double value that never change.
that makes the constant change in ways especified by the program,
its the same game,Im glad if this helps!
------------------------abyssphobia--------------------------
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.
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.
Another thing is you can make macros with #define
[Example]
Code:#define NIBBLE (Value & 0xF0) >> 4
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.
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.