|first of all, i shall thanks all of you guys.
In my project, i created some STATIC & EDIT controls in a CDialog and set these control's parent to a group box(also a STATIC control).
it works well for create, but it can't be delete dynamically.
For example, i create 5 EDIT control then delete it(there are no sub-controls in group box this time), and i create 2 EDIT control again, oops! there are 5 EDIT control showing in the group box. So, i guess this caused by the group box haven't refreshed in time. and then i sendmessage to group box to force it to refresh. unfortunately it doesn't works.
here is my code:
void CPLCDlg::DynamicCreateEdit(UINT nNums)
const int YSpace = 15;
const int EHeight = 20;
const UINT EDITID = 72000;
if (nNums <= 0)
CButton* pGroup = (CButton*)GetDlgItem(IDC_STATIC_GROUP);
if (NULL != pGroup)
if (NULL != m_pDynEdit && m_siNumsOfDynEdit > 0)
for (short i = 0; i < m_siNumsOfDynEdit; i++)
if (NULL != m_pDynEdit[i].GetSafeHwnd())
m_pDynEdit = NULL;
::SendMessage(pGroup->GetSafeHwnd(), WM_ERASEBKGND, 0, 0);
m_pDynEdit = new CEdit[nNums]();
for (short i = 0; i < nNums; i++)
rcPos.left = 10;
rcPos.top = 20 + (EHeight + YSpace) * i;
rcPos.right = rcPos.left + 30;
rcPos.bottom = rcPos.top + EHeight;
str.Format(_T("%d"), i + 1);
if (m_pDynEdit[i].CreateEx(WS_EX_STATICEDGE, _T("EDIT"), (LPCTSTR)str, ES_CENTER | WS_VISIBLE | WS_CHILD | WS_TABSTOP, rcPos, pGroup, EDITID + i))
m_siNumsOfDynEdit = nNums;