bsimser
asked on
Dynamic CStatics in a dialog
I'm porting an app from another system and have a function that adds strings to a stringlist then builds a dialog and displays it to the user (the original app is text based so it just does a setxy() then printf() to do the output). I figured I could do this in a dialog for the MFC version. So I created a dialog with a function to add a string to a stringlist. When it comes to displaying the dialog, I loop through the number of strings in the stringlist and display them (and resize the dialog based on the number of strings I have, 1 string per line in the dialog). Since I don't know up front how many lines of text I have, I assume I should create a CStatic for each string dynamically just before the dialog is created. I've tried doing this in InitDialog but it doesn't show up when the dialog is displayed. Any code samples would be appreciated. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks! I used your second idea of creating an array of CStatics and calling create for each one. Works perfectly.
ASKER
Thanks! I used your second idea of creating an array of CStatics and calling create for each one. Works perfectly.
as I said I created a Dialog base App from the scratch and in
the OnInitDialog I created dynamicly 2 CStatics with different
strings
The same should should work for you.
In the sample above I don't care about memory leaks
I simple create the CStatics without storing any reference them
you should hold the references to them to delete if your app
terminates
because you know the number of strings you can also
create the CStatics as
CStatic * MyTextStatics=new CStatic[NumberOfStrings];
and create them with
for(int i=0;i<NumberOfStrings;i++)
{
MyTextStatics[i].Create(St
CalcNextPosition;
}
hope that helps
Norbert