I'm sure this has a trivial answer ...
I have a set of buttons in a program that have related functions.
Working code:
Code:
#define IDC_BUTTON_S1 1501
#define IDC_BUTTON_S2 1502
#define IDC_BUTTON_S3 1503
...
#define IDC_BUTTON_S10 1510
... elsewhere in program ...
case WM_COMMAND:
{
switch(LOWORD(wParam)) {
case IDC_BUTTON_S1:
{
if( HIWORD(wParam) == BN_CLICKED ) {
// do stuff
return 0;
}
break;
}
case IDC_BUTTON_S2:
{
if( HIWORD(wParam) == BN_CLICKED ) {
// do stuff
return 0;
}
break;
}
...
For a few reasons, having ten separate IDC_BUTTON_S# entries is a pain, not the least of which is an inability to address them neatly in loops or otherwise by their #.
So what I want, and what I attempted, was this:
Code:
const int IDC_BUTTON_S[10] = { 1501, 1502, 1503, 1504, 1505, 1506, 1507, 1508, 1509, 1510 };
...
case WM_COMMAND:
{
switch(LOWORD(wParam)) {
case IDC_BUTTON_S[0]:
{
if( HIWORD(wParam) == BN_CLICKED ) {
// do stuff
return 0;
}
break;
}
case IDC_BUTTON_S[1]:
{
if( HIWORD(wParam) == BN_CLICKED ) {
// do stuff
return 0;
}
break;
}
...
But my compiler won't play that game. It complains:
error: case label does not reduce to an integer constant
I very much want to be able to do things like
Code:
for( i = 0; i < 10; i++ )
EnableWindow(GetDlgItem(hWnd,IDC_BUTTON_S[i]),TRUE);
or change the bitmap on one or more buttons without resorting to ugly switch/case statements and having to explicitly address them as IDC_BUTTON_S1, IDC_BUTTON_S2 ...
Should I be declaring my const int ICD_BUTTON_S[10] array differently?
Thank you.