khlauster
asked on
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(s tr197)
m_st_1_201.SetWindowText(s tr201)
…………………………………………
so on
please, provide a code sample if possible
thank you
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(s
m_st_1_201.SetWindowText(s
…………………………………………
so on
please, provide a code sample if possible
thank you
ASKER
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.F ormat(“%d” ,I));
}
thank you for your prompt suggestion
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.F
}
thank you for your prompt suggestion
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
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
ps. The DDX call can be inside a loop if you would rather use that method instead
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
The loop works.. just the controls drawing is slow!
I will appreciate any suggestion on how to accelerate it
my points up!
thank you
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
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
ASKER
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
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
You are welcome
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