Looping the resource IDs and references to the member variables

Is any way to loop through the resource IDs of the static control  and its references to the member variables of the dialog box.
If, for example I have 300 static controls:
DDX_Control(pDX, IDC_ST_1_1, m_st_1_1);
………………………………………………………
………………………………………………………
DDX_Control(pDX, IDC_ST_1_300, m_st_1_300);

Then I need to loop through the control Ids and references in order to set window text, which would depend on control’s ID and member variable:

m_st_1_197.SetWindowText(str197)
m_st_1_201.SetWindowText(str201)
…………………………………………
so on

please, provide a code sample if possible

thank you
khlausterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pgnatyukCommented:
I could ask why you didn't use CListCtrl, for example.

GetDlgItem, GetDlgItemText, SetDlgItemText will help you.

All these ID's you can find in your project and you will see their values. More about it:
Using Resources
http://www.winprog.org/tutorial/resources.html
If you prefer this way, this link will explain everything and help.
(FindResourceEx allow you to find all your resources.)

But maybe it will be better to create all these CStatic object in run-time and assign for them the ID's that you will control. For example, from a range from 10001 to 10300.
http://msdn.microsoft.com/en-us/library/kaw7w663(VS.80).aspx

Here is a tutorial
http://www.functionx.com/visualc/controls/statictext.htm
0
khlausterAuthor Commented:
Very well.. great info.
Now, to finalize my question, how do I I loop through UINT nIDs ?..
In the following loop, for example:


      CRELabel *Label = new CRELabel;
      Cstring str;
            
      For(int I = 0; I < 300; I ++)
{
Label->Create("Saint Lucia", WS_CHILD |  WS_VISIBLE,
                      CRect(10, 40, 160, 60), this, nID (I)?);

Label->SetWindowText(str.Format(“%d”,I));

}

thank you for your prompt suggestion
0
AndyAinscowFreelance programmer / ConsultantCommented:
If the resource ID's are in sequence to loop through is simple

for(UINT nID = IDC_STATIC_1; nID <= IDC_STATIC_300; nID++)
{
  CWnd* pControl = GetDlgItem(nID)
}


If the captions are also stored as string resources (which could be the same resource ID as the control they belong to then something like this can be in the loop

CString s;
s.LoadString(nID);  //load a string from the resource table with the ID
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

AndyAinscowFreelance programmer / ConsultantCommented:
ps.  The DDX call can be inside a loop if you would rather use that method instead
0
pgnatyukCommented:
I'd say:
CRELabel *Label[300];
Cstring str;
UINT nStart = 10101;
for(int I = 0; I < 300; I ++)
{
     Label[I] = new CRELabel;
     Label[I]->Create("Sirmione", WS_CHILD |  WS_VISIBLE,
                      CRect(10, 40, 160, 60), this, nStart + I);
     Label[I]->SetWindowText(str.Format(“%d”,I));
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
khlausterAuthor Commented:
pgnatyuk!

The loop works.. just the controls drawing is slow!
I will appreciate any suggestion on how to accelerate it
my points up!
thank you
0
pgnatyukCommented:
Because these are 300 controls. Each control is a window that has to draw itself.

I think you need to replace 300 controls with a list - a standard control like CListCtrl:
http://msdn.microsoft.com/en-us/library/hfshke78(VS.80).aspx
(Or make your own control).

Another way is to draw directly on the parent window - for example DrawText:
http://msdn.microsoft.com/en-us/library/a6x7y2a4(VS.80).aspx
0
khlausterAuthor Commented:
Thank you for your suggestions, pgnatyuk!

1. I can not use List control because I am planning to map image and put its pieces on those static controls then attach a few  event handlers to the controls, where i have to be able to loop through..

text was just as an example
0
pgnatyukCommented:
You are welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.