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个视,那更好了.
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个视,那更好了.
解决方案 »
- 如何提高tcp服务器的效率
- 一个不解的问题
- CTabCtrl中页面存储问题!!!急!!
- 如何在树控件中树各项的前面加图标??
- CreateProcess停Messenger服务
- 紧急求救!用Embeded VC++如何编写MP3文件播放程序?
- 大家来讨论一下学VC 应该怎样确立自已的方向呢?
- socket 中的send(s,buffer,length,flags)中的length会发送给服务器作为较证吗?
- 怎样使用用RTP协议!30分送大虾!
- MFC 鼠标滚轮如何实现图形放大缩小
- ★★★VS2005下,关于自定义资源文件的读取保存程序?解决后100分相送
- MSN实现界面用了特殊的DirectUI库,这套库的源代码哪里有下?
写错了,一句应改为
if(this->m_wndFrame.Create(NULL,"Frame",WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,NULL,0,NULL)!=TRUE)
你应该在堆上创建这个对象,或者重载OnPostNCDestroy,调用CWnd而不是CFrameWnd的基类实现。
{
if (::IsWindow(m_wndFrame.GetSafeHwnd()))
m_wndFrame.DestroyWindow();
CTestControlBar::OnDestroy();
}
如jiangsheng说的``CFrameWnd在PostNcDestroy有一句delete this,所以,你的wndFrame要定义为指针,释放的时候,只要DestroyWindow就行了,不要delete,还有就是你要在对话框的构造里将wndFrame初始为NULL,在OnSize里,MoveWindow时,先判断wndFrame是否不为NULL`
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();
}
吧.试了一下,好象还是出错.
/////////////////////////
如果m_wndFrame不定义为指针,则要按照jiangsheng说的改一下OnPostNCDestroy.