justin89h Posted June 26, 2004 Share Posted June 26, 2004 Using C++ (Visual C++), is there any particular way you can use a variable in accessing a control in a dialog? Eg (to clear a bunch of values of buttons): int i; for ( i = 1; i < 10; i++ ) { SetDlgItemText(hwnd, IDC_BTN<need 'i' here>, ""); } Anyone know how to do this, or get around it, or something? Link to comment Share on other sites More sharing options...
0 bwx Posted June 26, 2004 Share Posted June 26, 2004 Since the dialog identifiers are macro's and they are replaced with the actual numbers during compile-time, this is not possible. You're best bet would be something like: const int buttons[] = { IDC_BTN1, IDC_BTN2, IDC_BTN3 /* ... */ }; for(int i=0;i<( sizeof(buttons) / sizeof(buttons[0]) );++i) SetDlgItemText(hwnd, buttons[i], ""); hope that helps, bwx Link to comment Share on other sites More sharing options...
0 justin89h Posted June 26, 2004 Author Share Posted June 26, 2004 I get the idea, probably will make it simpler though. Generally I think your idea is to store each control in the array, then you can just access it within a loop using the array. I was actually confused, i was thinking the identifiers were handled like variables, not macro's, so thats why i thought i could do something like my example. Thanks for the help, I'll do something like that. Link to comment Share on other sites More sharing options...
Question
justin89h
Using C++ (Visual C++), is there any particular way you can use a variable in accessing a control in a dialog?
Eg (to clear a bunch of values of buttons):
int i; for ( i = 1; i < 10; i++ ) { SetDlgItemText(hwnd, IDC_BTN<need 'i' here>, ""); }Anyone know how to do this, or get around it, or something?
Link to comment
Share on other sites
2 answers to this question
Recommended Posts