0

I have 32 check boxes and I need to enable all of them. I can do them individually by using:

CButton* button;


button = (CButton *)GetDlgItem(IDC_CHECK1);
button->SetCheck(BST_CHECKED);
button = (CButton *)GetDlgItem(IDC_CHECK2);
button->SetCheck(BST_CHECKED);

...

Is there a way to do this for all at once or in a loop where I can increment the check number even though it is a define.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Pladnius Brooks
  • 1,248
  • 3
  • 19
  • 36
  • Use a container. You can always have one for the IDs and use `std::iota` to fill it if they're consecutive. – chris May 13 '13 at 23:38

1 Answers1

1

IDC_CHECK1 and IDC_CHECK2 are defined as DWORD in resource.h file, you can define them in a sequenced number, and then use a for loop to get them:

for(int index=0;index<100;index++)
{    
  CButton* button = (CButton *)GetDlgItem(baseid+index);
   .......
}
diwatu
  • 5,641
  • 5
  • 38
  • 61
  • That's a great point. Didn't even think about that. Thank you. I'll accept when I am able to. – Pladnius Brooks May 13 '13 at 23:42
  • Just be careful when you do that to make sure the numbers stay sequential. The resource editor can renumber items when you least expect it. Also if any of them get deleted or another one added, you have to remember to change the array. It would be safer to define class members associated with each check box so the compiler will help you stay safe. It's really hard to remember in a year or 2 where these type of dependencies lie. – edtheprogrammerguy May 13 '13 at 23:45