简体   繁体   中英

What does IDC_STATIC means in a resource.h file?

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?

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 (eg when calling GetDlgItem or GetDlgItemInt ).

Some controls rarely need to be identified in code. A prominent example is the Static Control 1 , 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 file 2 .


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 API 3 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM