controls with consecutive control ID
-
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); } }
-
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); } }
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++
-
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); } }
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
-
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++
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.