TestControlBar.hCFrameWnd m_wndFrame;////////////
TestControlBar.cppint 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个视,那更好了.

解决方案 »

  1.   

    if(this->m_wndFrame.Create("BUTTON","Frame",WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,NULL,0,NULL)!=TRUE) 
     写错了,一句应改为
    if(this->m_wndFrame.Create(NULL,"Frame",WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,NULL,0,NULL)!=TRUE)
      

  2.   

    框架在销毁时默认是要delete this的,你把它作为栈上的成员变量来用的话会造成出错
    你应该在堆上创建这个对象,或者重载OnPostNCDestroy,调用CWnd而不是CFrameWnd的基类实现。
      

  3.   

    void CTestControlBar::OnDestroy()
    {
    if (::IsWindow(m_wndFrame.GetSafeHwnd()))
    m_wndFrame.DestroyWindow();
    CTestControlBar::OnDestroy();
    }
      

  4.   

    jiangsheng(蒋晟.Net[MVP])  强。。`你是没有看程序的吧?
    如jiangsheng说的``CFrameWnd在PostNcDestroy有一句delete this,所以,你的wndFrame要定义为指针,释放的时候,只要DestroyWindow就行了,不要delete,还有就是你要在对话框的构造里将wndFrame初始为NULL,在OnSize里,MoveWindow时,先判断wndFrame是否不为NULL`
      

  5.   

    to jiangsheng:我这样修改了一下
    void CTestFrameWnd::PostNcDestroy()
    {
    // TODO: Add your specialized code here and/or call the base class
       CWnd::PostNcDestroy();
    //CFrameWnd::PostNcDestroy();
    }
    不会出错了.////////////
    To yjgx007:应该是
    void CTestControlBar::OnDestroy()
    {
        if (::IsWindow(m_wndFrame.GetSafeHwnd()))
           m_wndFrame.DestroyWindow();
        CControlBar::OnDestroy();
    }
    吧.试了一下,好象还是出错.
    /////////////////////////
      

  6.   

    to CrazyAzreal:我将m_wndFrame定义为指针试试看.
      

  7.   

    试了一下,将m_wndFrame定义为指针,就不会出错了.CrazyAzreal,你说的"你的m_wndFrame要定义为指针,释放的时候,只要DestroyWindow就行了,不要delete,",释放指的是在m_wndFrame的父窗口中释放吗?
    如果m_wndFrame不定义为指针,则要按照jiangsheng说的改一下OnPostNCDestroy.
      

  8.   

    多看看微软的MFC、ATL和.Net框架的源代码,对自己写程序有好处