简体   繁体   English

IDC_STATIC 在resource.h 文件中是什么意思?

[英]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:我有一个由 VS 2012 生成的简单 Win32 项目。在resource.h文件中,我看到了这个:

#ifndef IDC_STATIC
#define IDC_STATIC              -1
#endif

I found it is been referenced in a couple places in the resource.rc file.我发现它在resource.rc文件中的几个地方被引用。 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).通过调用CreateWindowEx创建子控件时,您必须分配一个控件 ID(通过重载的hMenu参数)。 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 ).以后可以使用控件 ID 来引用控件,而不必存储动态创建的HWND (例如,在调用GetDlgItemGetDlgItemInt )。

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.一个突出的例子是静态控件1 ,如果在资源脚本中定义,通常不需要在代码中引用。 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.您(或对话框管理器)在创建控件时仍需要传递控件 ID,即使您以后不使用它。 For those controls you can pass the IDC_STATIC control ID, that is defined in a wizard-generated Resource.h file 2 .对于这些控件,您可以传递IDC_STATIC控件 ID,该 ID 在向导生成的Resource.h文件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 . 1其他示例包括图标控件(具有SS_ICON样式的静态控件)、 行控件(具有SS_ETCHEDHORZSS_SUNKEN样式的静态控件)或GroupBox 控件

2 This is not a convention of the Windows API 3 . 2这不是 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如果需要,您可以使用另一个 ID 值,或者根本不定义IDC_STATIC ,而在LTEXT 控制语句中使用整数文字: 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. 3当然,SDK 头文件winres.h确实将预处理器符号IDC_STATIC定义为(-1) ,因此如果您在代码中定义它,请确保分配相同的值以避免任何混淆。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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