Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Convert string name to Control ID Name

Convert string name to Control ID Name

Scheduled Pinned Locked Moved C / C++ / MFC
8 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 0 Offline
    0 Offline
    002comp
    wrote on last edited by
    #1

    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

    L L 4 Replies Last reply
    0
    • 0 002comp

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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?

      0 1 Reply Last reply
      0
      • L Lost User

        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?

        0 Offline
        0 Offline
        002comp
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • 0 002comp

          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.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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.

          L 1 Reply Last reply
          0
          • L Lost User

            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.

            L Offline
            L Offline
            leon de boer
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • 0 002comp

              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

              L Offline
              L Offline
              leon de boer
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • 0 002comp

                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

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                How are you creating all these buttons? Anytime I need more than a few of the same type, I create them dynamically and add their references to a collection. You then reference them via an "index" (which is the equivalent of an ID).

                1 Reply Last reply
                0
                • 0 002comp

                  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

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  I think control array will help you.

                  void CControlArrayDlg::DoDataExchange(CDataExchange* pDX)
                  {
                  CDialogEx::DoDataExchange(pDX);
                  DDX_Control(pDX, IDC_BUTTON1, m_CtrlButton[0]);
                  DDX_Control(pDX, IDC_BUTTON2, m_CtrlButton[1]);
                  }

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups