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?
 
pgnatyukConnect With a Mentor Commented:
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
 
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
AndyAinscowFreelance programmer / ConsultantCommented:
ps.  The DDX call can be inside a loop if you would rather use that method instead
0
 
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
All Courses

From novice to tech pro — start learning today.