Solved

Dialog controls / member variables

Posted on 1998-11-13
5
218 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using Delphi code in a Builder project that uses a DLL 3 110
Converting to C# also VS2015 5 117
SendMessage fails while PostMessage works 2 107
Lambda for random numbers problem 7 107
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. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

920 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

17 Experts available now in Live!

Get 1:1 Help Now