Convert string name to Control ID Name
-
Hello Friends I am creating 100s of buttons in Window application.I used naming like IDB_BUTTON1, IDB_BUTTON2..... IDB_BUTTON100.And assign variable m_button1. Now, I want to convert string (m_button+ ID) to m_button1 of CButton type. Regards
-
You cannot normally do that, generated resource IDs are numbers. You can use strings to refer to resources but it requires a detailed knowledge of resource files and the rc compiler. This also begs the question, why do you need so many buttons?
So many buttons are requirement of Application. Actually, I tried with Macro. But ,again I need to use Variable value to identify 100 buttons tht macro doesn't consider variable. I used like #define CONCAT(ID,NUMBER) ID##NUMBER And IN Code for(int num =0; num < 100; num++) CONCAT(m_Button,num) So, this one fails.
-
So many buttons are requirement of Application. Actually, I tried with Macro. But ,again I need to use Variable value to identify 100 buttons tht macro doesn't consider variable. I used like #define CONCAT(ID,NUMBER) ID##NUMBER And IN Code for(int num =0; num < 100; num++) CONCAT(m_Button,num) So, this one fails.
-
Like I said, you cannot do it, as resource ids are integer values. And chances are if the application needs 100 buttons, then there is something wrong with the design.
I beg to disagree on some grid based applications I routinely get up over 200 buttons but there are tricks which I will discuss with him.
In vino veritas
-
Hello Friends I am creating 100s of buttons in Window application.I used naming like IDB_BUTTON1, IDB_BUTTON2..... IDB_BUTTON100.And assign variable m_button1. Now, I want to convert string (m_button+ ID) to m_button1 of CButton type. Regards
I suspect you need all the buttons for something like I have done which was a grid display for a process plant control switches for pumps and the like. What you can do is attach a text string as either a property of the button handle via "SetProp" or alternative set the string as a resource using RT_STRING to the ID of the button and use FindResourceEx to pull back the string matching the button ID. The String resources are stored in sections of up to 16 strings per section so you will need to provide a function to pull it back. Here is a sort of normal code for pulling back a string resource String Resources | Ruminations[^] The SetProp way is easier but can only be created in the WM_CREATE of the button creation, or just after the CreateWindowEx call creating the button and so needs a little more setup work than a string resource list.
In vino veritas
-
Hello Friends I am creating 100s of buttons in Window application.I used naming like IDB_BUTTON1, IDB_BUTTON2..... IDB_BUTTON100.And assign variable m_button1. Now, I want to convert string (m_button+ ID) to m_button1 of CButton type. Regards
-
Hello Friends I am creating 100s of buttons in Window application.I used naming like IDB_BUTTON1, IDB_BUTTON2..... IDB_BUTTON100.And assign variable m_button1. Now, I want to convert string (m_button+ ID) to m_button1 of CButton type. Regards