Question

I have to show/enable a bunch of dialog items in an MFC application. 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.

Is it possible to get the resourceId named IDC_EDIT_CHANNEL1_1, from a string "IDC_EDIT_CHANNEL1_1"?

As you all know GetDlgItem() only works with int values.

Était-ce utile?

La solution

The problem you don't see is that the preprocessor replaces IDC_EDIT_CHANNEL1_x with an integer at compile time. 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. 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. You can filter them by string then.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top