Storing string in CStatic

Posted by Shark on Stack Overflow See other posts from Stack Overflow or by Shark
Published on 2010-05-05T08:12:28Z Indexed on 2010/05/05 8:18 UTC
Read the original article Hit count: 204

Filed under:
|

I have to create dynamically allocated array of CStatic (CStatic* array;), which then displayed on the dialog. It must be allocated and filled like this:

array = new CStatic[list_box.GetCount()];
 for (int i = 0; i < list_box.GetCount(); i++) {
  CString str;
  list_box.GetText(i, str);
  array[i].Create(str, WS_CHILD, CRect(), GetParent());
 }

But str is destroyed after the dialog is closed, because list_box destroyes too, and all pointers inside CStatics points nowhere (I assume it is not working because of this). What can I do to fix this? Any help would be appreciated.

P.S. I know, that this is awful way and this is all wrong and I know how to do this right, but unfortunately, I can't change tasks, they give us in the university :)

© Stack Overflow or respective owner

Related posts about mfc

Related posts about cstring