MFC - 资源 ID 唯一性

2022-01-12 00:00:00 visual-c++ mfc

我正在使用外部资源开发 MFC 应用程序.

I'm working on an MFC application, using external resources.

resource.h 文件已由其他开发人员手动编辑,我发现存在冲突的 ID.

The resource.h file has been manually edited by other developers and I've seen that there are conflicting IDs.

我见过微软 TN020:ID 命名和编号约定.

我只是想知道控件和其他资源的 ID(不包括字符串)在整个应用程序中是否必须是唯一的,或者如果它们对于每个定义的对话框都是唯一的就足够了.

I was just wondering if the IDs for controls and other resources (strings excluded) must be unique in the whole application or it's just enough if they are unique for each defined dialog.

推荐答案

同一个对话框中的两个控件必须有不同的ID(使用IDC_STATIC时除外,即-1,在资源编辑器中).不同对话框中的两个控件可以具有相同的 ID,ID 为 IDOKIDCANCEL 的按钮就是很好的例子.

Two controls in the same dialog must have different IDs (except when using IDC_STATIC, which is -1, in the resource editor). Two controls in different dialogs can have the same ID, good examples for that are buttons with the IDs IDOK and IDCANCEL.

相关文章