1

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 Oct 14 '16 at 11:41
  • 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)) – Сергей Соколов Oct 14 '16 at 11:56
  • 2
    Why would a `CString` with the value of a compile-time constant be useful? What problem are you trying to solve? – IInspectable Oct 14 '16 at 11:58
  • Because I want to separate resources with texts from code, for localization. Using this tool: http://www.codeproject.com/Articles/3711/RC-Localization-Tool-LocalizeRC – Сергей Соколов Oct 14 '16 at 12:20
  • @СергейСоколов you probably misread/misunderstood something in the codeproject article. – Jabberwocky Oct 14 '16 at 13:09
  • The program from article is very good, and I using it successfully. But in my code, I have a lot of texts. And I want to send them to resource file (to string table). And It will be very useful for me to call them like CString(MAKEINTRESOURCE(converted string)), not CString(MAKEINTRESOURCE(ID)) – Сергей Соколов Oct 14 '16 at 13:50
  • You've got this backwards. You **should** be using the resource ID, but load the respective (resource-only) DLL based on the selected language. MFC does most of this for you already anyway (see [Localized Resources in MFC Applications: Satellite DLLs](https://msdn.microsoft.com/en-us/library/8fkteez0.aspx)). For a more complete introduction see [Multiple-Language Resources](https://msdn.microsoft.com/en-us/library/cc194810.aspx) (applies to MFC just as well). – IInspectable Oct 14 '16 at 14:29
  • IInspectable - thank you, I have read the article about Satellite DLLs. The question is, that I have many situations in my application, that looks smth like: if (field_name="fieldname") {SetColumnText(CString(MAKEINTRESOURCE(ID)))} So, I want to do something like: if (field_name="fieldname") {SetColumnText(CString(MAKEINTRESOURCE(_field_name_converted_to_UINT)))}, so I can store my field names in a string table, may be in satellite dll. – Сергей Соколов Oct 14 '16 at 14:57
  • 1
    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](http://stackoverflow.com/q/388242/1889329) on writing C++ code. That's an anti-pattern right there. – IInspectable Oct 14 '16 at 16:27

1 Answers1

0

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

Pavan Chandaka
  • 11,671
  • 5
  • 26
  • 34