Solved

Dialog controls / member variables

Posted on 1998-11-13
5
216 Views
Last Modified: 2010-04-02
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 ?
0
Comment
Question by:decornez
5 Comments
 

Expert Comment

by:dinom
ID: 1177848
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
 
LVL 4

Expert Comment

by:pagladasu
ID: 1177849
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
 

Author Comment

by:decornez
ID: 1177850
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
 

Accepted Solution

by:
McCreary earned 30 total points
ID: 1177851
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
 

Author Comment

by:decornez
ID: 1177852
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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now