I've created a dialog based MFC app which input from user to create that many dynamic controls(Used checkbox to be created dynamically).
After user input that many checkboxes controls are created but if try to click again then not able to delete previous controls and again new no. of controls.
Code snippet to add controls on usre input.
RECT rctA;
rctA.top = 51;
rctA.bottom = 80;
CString temp;
m_Edit.GetWindowText(temp);
int noOfControls = _tstoi(temp);
for(int i=0;i < noOfControls; ++i)
{
m_CheckBox[i].Create(_T(""), WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX ,
CRect(10,rctA.top,30,rctA.bottom ), this, 1+i);
rctA.top+=30;
rctA.bottom+=30;
}