简体   繁体   English

通过字符串获取对话框项的可能性

[英]Possibility to get a Dialog Item via string

I have to show/enable a bunch of dialog items in an MFC application. 我必须在MFC应用程序中显示/启用一堆对话框项。 They all have names like IDC_EDIT_CHANNEL1_x , where x is an int value from 0 to 15. The IDs from the resource file are not ordered so I want to get the items by that string. 它们都具有IDC_EDIT_CHANNEL1_x名称,其中x是从0到15的整数值。资源文件中的ID没有排序,因此我想通过该字符串获取项目。

Is it possible to get the resourceId named IDC_EDIT_CHANNEL1_1 , from a string "IDC_EDIT_CHANNEL1_1" ? 是否可以从字符串"IDC_EDIT_CHANNEL1_1"获取名为IDC_EDIT_CHANNEL1_1的resourceId?

As you all know GetDlgItem() only works with int values. 众所周知,GetDlgItem()仅适用于int值。

The problem you don't see is that the preprocessor replaces IDC_EDIT_CHANNEL1_x with an integer at compile time. 您没有看到的问题是预处理器在编译时将IDC_EDIT_CHANNEL1_x替换为整数。 This is a macro, not a string. 这是一个宏,而不是字符串。

So your application never "sees" a string. 因此,您的应用程序永远不会“看到”字符串。 The string has been substituted by the preprocessor before the source code reaches the compiler. 在源代码到达编译器之前,该字符串已由预处理器替换。

My advice is to use consecutive IDs. 我的建议是使用连续的ID。 I don't know why you don't want to do that, but it will probably be the quickest and most straightforward way to solve your problem. 我不知道您为什么不想这样做,但这可能是解决问题的最快,最直接的方法。

The other way is to not use macros at all. 另一种方法是根本不使用宏。 The resource editor can use strings, and if the preprocessor doesn't replace them with ints, that's what will be used. 资源编辑器可以使用字符串,如果预处理器未将它们替换为int,则将使用该字符串。 You can filter them by string then. 然后可以按字符串过滤它们。

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

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