CFrameWnd作为子窗口在CControlBar中创建的有关问题

CFrameWnd作为子窗口在CControlBar中创建的问题
TestControlBar.h

CFrameWnd   m_wndFrame;

////////////
TestControlBar.cpp

int   CTestControlBar::OnCreate(LPCREATESTRUCT   lpCreateStruct)
{
if   (CControlBar::OnCreate(lpCreateStruct)   ==   -1)
return   -1;

//   TODO:     Add   your   specialized   creation   code   here

if(this-> m_wndFrame.Create( "BUTTON ", "Frame ",WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,NULL,0,NULL)!=TRUE)
{
AfxMessageBox( "Create   frame   error! ");
return   0;
}
this-> SendMessage(WM_SIZE,0,0);

return   0;
}

void   CTestControlBar::OnSize(UINT   nType,   int   cx,   int   cy)
{
CControlBar::OnSize(nType,   cx,   cy);

//   TODO:   Add   your   message   handler   code   here
if(this-> m_wndFrame.m_hWnd   )
{
CRect   rc;
this-> GetClientRect(&rc);
this-> m_wndFrame.MoveWindow(rc,TRUE);
}
}

////////////
程序可正常显示m_wndFrame,但是程序退出时出错,调试了一下,可能是销毁m_wndFrame时出错了,但未找到确切的原因.CFrameWnd作为子窗口创建时,是不是要做某些特殊设置.我之所以将CFrameWnd作为CControlBar的子窗口创建,是想通过CFrameWnd使CControlBar看起来切分成2个视(在CFrameWnd::OnCreateClient中使用CSplitterWnd切分).当然,如果有直接的方法将CControlbar切分成2个视,那更好了.

------解决方案--------------------
框架在销毁时默认是要delete this的,你把它作为栈上的成员变量来用的话会造成出错
你应该在堆上创建这个对象,或者重载OnPostNCDestroy,调用CWnd而不是CFrameWnd的基类实现。
------解决方案--------------------
void CTestControlBar::OnDestroy()
{
if (::IsWindow(m_wndFrame.GetSafeHwnd()))
m_wndFrame.DestroyWindow();
CTestControlBar::OnDestroy();
}
------解决方案--------------------
jiangsheng(蒋晟.Net[MVP]) 强。。`你是没有看程序的吧?
如jiangsheng说的``CFrameWnd在PostNcDestroy有一句delete this,所以,你的wndFrame要定义为指针,释放的时候,只要DestroyWindow就行了,不要delete,还有就是你要在对话框的构造里将wndFrame初始为NULL,在OnSize里,MoveWindow时,先判断wndFrame是否不为NULL`