IDC_STATIC 在resource.h 文件中是什么意思? [英] What does IDC_STATIC means in a resource.h file?

查看:61
本文介绍了IDC_STATIC 在resource.h 文件中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由 VS 2012 生成的简单 Win32 项目.在 resource.h 文件中,我看到了这个:

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

我发现它在 resource.rc 文件中的几个地方被引用.但我无法理解这意味着什么.我也没有在网上找到有关它的参考.有什么想法吗?

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?

推荐答案

通过调用 CreateWindowEx,您必须分配一个控件 ID(通过重载的 hMenu 参数).以后可以使用控件 ID 来引用控件,而不必存储动态创建的 HWND(例如,在调用 GetDlgItemGetDlgItemInt).

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).

有些控件很少需要在代码中标识.一个突出的例子是静态控制1,即,如果在资源脚本中定义,通常不需要在代码中引用.您(或对话框管理器)在创建控件时仍需要传递控件 ID,即使您以后不使用它.对于这些控件,您可以传递 IDC_STATIC 控件 ID,该 ID 在向导生成的 Resource.h 文件2 中定义sup>.

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 其他示例包括 图标控件(具有 SS_ICON 样式的静态控件),Line Control(具有 SS_ETCHEDHORZSS_SUNKEN 样式的静态控件),或 GroupBox 控件.

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 这不是 Windows API3 的约定.这严格是由用户代码做出的决定.如果需要,您可以使用另一个 ID 值,或者根本不定义 IDC_STATIC,并在 LTEXT 控制语句:LTEXT "Filename", -1, 10, 10, 100, 100

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 当然,SDK 头 winres.h 确实将预处理器符号 IDC_STATIC 定义为(-1),因此如果您确实在代码中定义了它,请确保分配相同的值以避免任何混淆.

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.

这篇关于IDC_STATIC 在resource.h 文件中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆