Dialog controls / member variables

I currently use the classwizard to add menber variables to the different controls I have within a dialog box. For example I would create a member variable like let's say "m_HkdBid1" which would be linked to an edit box.

Now the problem I have is that in some dialog boxes, I have a lot of edit boxes which I have to initialize one by one and it is not very efficient. I would like to declare my control name and member variables names as part as an array so that I can later use a fast loop to initialize them. But at the moment class wizard would not let me name a member variable something like m_HkdBid[1] (it seems the square brackets are illegal characters in this case). Same question with the name of the controls. So in short, how can I declare controls' name and member variables names which are part of an array of data ?
decornezAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
McCrearyConnect With a Mentor Commented:
Put something like this in OnInitDialog()
#define NUM_VALUES 3
static UNIT idc[NUM_VALUES] = {IDC_CONTROL1, IDC_CONTROL2, IDC_CONTROL3};
char text[128];

for ( short i=0; i<NUM_VALUES)
{
    sprintf(value, "%d", value[i]);   // or whereever your value comes from
    GetDlgItem(idc[i])->SetWindowText(text);
}

If the static arrary idc is outside the scope of the OnInitDialog, you can use the inverse code to put the text from the controls back into the values in OnOK()


0
 
dinomCommented:
Do you think you could forego using classwizard by adding code by hand.  That is add an array member variable (i.e. an array of CStirngs) then place approriate loops around the macros that classwizard would have generated (i.e. validation and initialization).  Examine how class wizard goes about adding the class member, I think it just adds the class member and couple of macros into the constructor for data initialization and a few macros into the data validation routine, then reproduce what classwizard would have done but with your loops and an array.  I can't really see why this wouldn't work.  Again, your problem seems to be that your not too sure exactly what classwizard does when you add a control and associate it with a class member.
0
 
pagladasuCommented:
You can declare an array of pointers say
CString *values[10];
CEdit *controls[10];
Then in the constructor, make each pointer point to the appropraite members.
values[0]=&m_editvalue1;
controls[0]=&m_editctrl1;
And the use the array members to manipulate data and controls.
Thanks and best of luck.
pagladasu
0
 
decornezAuthor Commented:
pagladasu,

thanks for proposed answer. Unfortunately, I still cannot loop to initialize my variables as we still have m_editvalue1, m_editvalue2...etc

dinom,

I have tried this approach. I can replicate what the viewer does manually and declaring arrays of variables instead of a group of single variables, but After I do that, although the code runs, my viewer goes bezerk every time I try to work on the design of my dialog, and I cannot anything without getting loads of warning messages.
So basically, I do not think that it is feasible given the way MS VC++ 5 is build.
I wonder if version 6 can cater for this type of situation.

Anyway, thanks to both of you for your time and effort.
A.
0
 
decornezAuthor Commented:
McCreary,

Thanks for your answer. By actually making the controls part of an array and then looping through, it allows me to initialize all the data rather fast.

So well done, the points are yours.

Rgds,
A.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.