Reputation: 11200
I have a simple Win32 project generated by VS 2012. In the resource.h
file, I saw this:
#ifndef IDC_STATIC
#define IDC_STATIC -1
#endif
I found it is been referenced in a couple places in the resource.rc
file. But I could not understand what it means. Neither did I find reference about it online. Any idea?
Upvotes: 9
Views: 5768
Reputation: 51503
When creating child controls by calling CreateWindowEx
, you have to assign a control ID (through the overloaded hMenu parameter). The control ID can later be used to refer to a control, without having to store the dynamically created HWND
(e.g. when calling GetDlgItem
or GetDlgItemInt
).
Some controls rarely need to be identified in code. A prominent example is the Static Control1, that, if defined in a resource script, usually does not need to be referenced in code. You (or the dialog manager) still need to pass a control ID when creating the control, even though you don't use it later on. For those controls you can pass the IDC_STATIC
control ID, that is defined in a wizard-generated Resource.h
file2.
1 Other examples include the Icon Control (a static control with the SS_ICON
style), the Line Control (a static control with the SS_ETCHEDHORZ
and SS_SUNKEN
styles), or the GroupBox Control.
2 This is not a convention of the Windows API3. It is strictly a decision made by user code. You could use another ID value, or not define IDC_STATIC
at all if you want, and use an integer literal in the LTEXT control statement instead: LTEXT "Filename", -1, 10, 10, 100, 100
3 Granted, the SDK header winres.h
does define the preprocessor symbol IDC_STATIC
as (-1)
, so if you do define it in your code, make sure to assign the same value to avoid any confusion.
Upvotes: 4