Click to See Complete Forum and Search --> : Dynamic Creation of CStatic Control


Mark Zielinski
May 29th, 1999, 10:18 AM
I am trying to create some dynamic static controls within a dialog box. I have found one function that works but the other does not. I would like to use Create instead of CreateWindow. Create Window works, Create is not displaying the text.

Here is the example. Any help would be appreciated.

int CDynamicDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;

// TODO: Add your specialized creation code here
// This works
CreateWindow("static", "Text from CreateWindow", WS_CHILD | WS_VISIBLE,
10,10,300,20, m_hWnd, (HMENU)11, 0, NULL);

// This does not work
CStatic m_Text;
m_Text.Create(_T("Text From Create"), WS_CHILD | WS_VISIBLE,
CRect(100,100,300,20), this, 12 );

return 0;
}

Wayne Fuller
May 29th, 1999, 12:02 PM
First of all, if your code in the program is exactly like you wrote in the message, CStatic is a local, when it exits the function it destroys itself. Move CStatic declaration to the header file.

Wayne

Mark Zielinski
May 29th, 1999, 12:25 PM
Thank you, it took care of the problem.