• 0

Control Names


Question

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

  • 0

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

  • 0

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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.