1
votes

I have some ID in MFC application, e.g.:

#define IDC_BUTTON1                     1002

And I have some functions in APP, using this ID, e.g.:

GetDlgItem(IDC_BUTTON1)->SetWindowPos(NULL,cx-750,cy-100,90,40,NULL);

Can I convert CString, like "IDC_BUTTON1" to use it dynamically? I want to do something like this:

GetDlgItem(_converted_string_)->SetWindowPos(NULL,cx-750,cy-100,90,40,NULL);

Conversion (atoi or smth.) from "1002" is not a variant.

1
IDC_BUTTON1 is a symbol, that exists during compilation only. Once the final executable image is generated, there are no traces left behind. So no, there is no way to do what you're asking for. Why would you need that? What is your specific scenario? - IInspectable
I have a lot of strings in a string table. It will be useful for me to call them like CString(MAKEINTRESOURCE(converted string)), not CString(MAKEINTRESOURCE(ID)) - Сергей Соколов
Why would a CString with the value of a compile-time constant be useful? What problem are you trying to solve? - IInspectable
Because I want to separate resources with texts from code, for localization. Using this tool: codeproject.com/Articles/3711/RC-Localization-Tool-LocalizeRC - Сергей Соколов
You need to drop those bad habits, probably picked up from writing too much PHP or JavaScript code. A string is not your universal datatype in C++. If you have code that reads if (field_name=="fieldname"), get a good book on writing C++ code. That's an anti-pattern right there. - IInspectable

1 Answers

0
votes

"IDC_BUTTON1" is not a string type.

It is an object like macro.

You can not apply string functions/operations on object like macros.

object like macros are identifiers, which will be replaced by a code fragment (by definition).