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. controls with consecutive control ID

controls with consecutive control ID

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
4 Posts 4 Posters 0 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.
  • E Offline
    E Offline
    elephantstar
    wrote on last edited by
    #1

    I have a 3x5 text box entries. Each are identified by almost the same number but with a different number attached to it. For example, row 1 control IDs are IDC_Row1_1, IDC_Row1_2, IDC_Row1_3, etc. I would like to disable/enable the boxes in a for loop without having to type out each control ID. How do I convert the string into the ControlID recognized by the system? See below. CString str; for (i = 1; i <= 3; i++) { for (j = 1; j <= 5; j++) { str = "IDC_Row" + i + "_" + j; //how do i convert the string to the control ID value to set its property? GetDlgItem(str)->EnableWindow(TRUE); } }

    C J 2 Replies Last reply
    0
    • E elephantstar

      I have a 3x5 text box entries. Each are identified by almost the same number but with a different number attached to it. For example, row 1 control IDs are IDC_Row1_1, IDC_Row1_2, IDC_Row1_3, etc. I would like to disable/enable the boxes in a for loop without having to type out each control ID. How do I convert the string into the ControlID recognized by the system? See below. CString str; for (i = 1; i <= 3; i++) { for (j = 1; j <= 5; j++) { str = "IDC_Row" + i + "_" + j; //how do i convert the string to the control ID value to set its property? GetDlgItem(str)->EnableWindow(TRUE); } }

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Your names are actually constant values, which map to numbers in your resource file. Your best bet is to make sure they are sequential in your resource files, and then you can just use a loop. Or you can create a vector which contains all the controls, regardless of their values, and a function object to pass to for_each. Christian Graus - Microsoft MVP - C++

      B 1 Reply Last reply
      0
      • E elephantstar

        I have a 3x5 text box entries. Each are identified by almost the same number but with a different number attached to it. For example, row 1 control IDs are IDC_Row1_1, IDC_Row1_2, IDC_Row1_3, etc. I would like to disable/enable the boxes in a for loop without having to type out each control ID. How do I convert the string into the ControlID recognized by the system? See below. CString str; for (i = 1; i <= 3; i++) { for (j = 1; j <= 5; j++) { str = "IDC_Row" + i + "_" + j; //how do i convert the string to the control ID value to set its property? GetDlgItem(str)->EnableWindow(TRUE); } }

        J Offline
        J Offline
        John M Drescher
        wrote on last edited by
        #3

        I started giving you a complicated solution (by trying to fix your code) that in the end would not work. Then thought about it for a few seconds and I have come to the conclusion that the best solution is the one Christian has provided above. I have used this method in the past (with buttons -phone dial pad) and it works great. [EDIT] One thing to add is I would edit the resource.h file directly. [/EDIT] John

        1 Reply Last reply
        0
        • C Christian Graus

          Your names are actually constant values, which map to numbers in your resource file. Your best bet is to make sure they are sequential in your resource files, and then you can just use a loop. Or you can create a vector which contains all the controls, regardless of their values, and a function object to pass to for_each. Christian Graus - Microsoft MVP - C++

          B Offline
          B Offline
          Blake Miller
          wrote on last edited by
          #4

          On the other hand, in the event that some other nitwit comes along and does not KNOW they have to be in order, you can declare a static array of UINT in your source file containing the identifiers, and use that as the basis for your looping. static UINT s_ControlArray[] = { IDC_CONTROL_1_1, IDC_CONTROL_1_2, IDC_CONTROL_1_3, IDC_CONTROL_2_1, IDC_CONTROL_2_2, IDC_CONTROL_2_3 }; Use a for loop to access the elements in the array. The GetDlgItem() would work using those identifier values, and then you can use the EnableItem as you wanted.

          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