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个视,那更好了.