我在设计一个软件,使单文档的程序,主页面显示的是一些画图的曲线(在对话框中固定了,不能改变大小)因此我想通控制按钮,如一个“新增窗口”命令来动态新建一个窗口(目前已经实现)。问题是我想在新建的窗口中实现静态拆分,我将如下代码加入我新建窗口的视类中,执行后没有效果。是不是我用于新建窗口的Frame模板是CMainFrame的原因,还是拆分只能在CMainFrame中实现不能在view类中实现?请高手指点,并帮助解决多谢!int CSp2View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1; // TODO: 在此添加您专用的创建代码 // //获得窗口的创建信息指针
CCreateContext *pContext=(CCreateContext*) lpCreateStruct->lpCreateParams;
if (!m_wndSplitter.CreateStatic(this, 1, 2))
{
TRACE0("Failed to CreateStaticSplitter\n");
return -1;
} // add the first splitter pane - the default view in column 0
if (!m_wndSplitter.CreateView(0, 0,
pContext->m_pNewViewClass, CSize(400, 0), pContext))
{
TRACE0("Failed to create first pane\n");
return -1;
} // add the second splitter pane - which is a nested splitter with 2 rows
if (!m_wndSplitter2.CreateStatic(
&m_wndSplitter, // our parent window is the first splitter
3, 1, // the new splitter is 2 rows, 1 column
WS_CHILD | WS_VISIBLE | WS_BORDER, // style, WS_BORDER is needed
m_wndSplitter.IdFromRowCol(0, 1)
// new splitter is in the first row, 2nd column of first splitter
))
{
TRACE0("Failed to create nested splitter\n");
return -1;
} // now create the two views inside the nested splitter
//int cyText = max(lpcs->cy - 70, 20); // height of text pane if (!m_wndSplitter2.CreateView(0, 0,
RUNTIME_CLASS(CSpeedView), CSize(0, 150), pContext))
{
TRACE0("Failed to create second pane\n");
return -1;
}
if (!m_wndSplitter2.CreateView(1, 0,
RUNTIME_CLASS(CGearView), CSize(0, 150), pContext))
{
TRACE0("Failed to create third pane\n");
return -1;
}
if (!m_wndSplitter2.CreateView(2, 0,
RUNTIME_CLASS(CHeartView), CSize(0, 0), pContext))
{
TRACE0("Failed to create third pane\n");
return -1;
}
return 0;
}
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1; // TODO: 在此添加您专用的创建代码 // //获得窗口的创建信息指针
CCreateContext *pContext=(CCreateContext*) lpCreateStruct->lpCreateParams;
if (!m_wndSplitter.CreateStatic(this, 1, 2))
{
TRACE0("Failed to CreateStaticSplitter\n");
return -1;
} // add the first splitter pane - the default view in column 0
if (!m_wndSplitter.CreateView(0, 0,
pContext->m_pNewViewClass, CSize(400, 0), pContext))
{
TRACE0("Failed to create first pane\n");
return -1;
} // add the second splitter pane - which is a nested splitter with 2 rows
if (!m_wndSplitter2.CreateStatic(
&m_wndSplitter, // our parent window is the first splitter
3, 1, // the new splitter is 2 rows, 1 column
WS_CHILD | WS_VISIBLE | WS_BORDER, // style, WS_BORDER is needed
m_wndSplitter.IdFromRowCol(0, 1)
// new splitter is in the first row, 2nd column of first splitter
))
{
TRACE0("Failed to create nested splitter\n");
return -1;
} // now create the two views inside the nested splitter
//int cyText = max(lpcs->cy - 70, 20); // height of text pane if (!m_wndSplitter2.CreateView(0, 0,
RUNTIME_CLASS(CSpeedView), CSize(0, 150), pContext))
{
TRACE0("Failed to create second pane\n");
return -1;
}
if (!m_wndSplitter2.CreateView(1, 0,
RUNTIME_CLASS(CGearView), CSize(0, 150), pContext))
{
TRACE0("Failed to create third pane\n");
return -1;
}
if (!m_wndSplitter2.CreateView(2, 0,
RUNTIME_CLASS(CHeartView), CSize(0, 0), pContext))
{
TRACE0("Failed to create third pane\n");
return -1;
}
return 0;
}
{
TRACE0("Failed to CreateStaticSplitter\n");
return -1;
}
this->GetDocument()->UpdateAllViews(NULL);
运行结果跟没加一样,还是 拆分条可以拖动,但是拖过的痕迹也保留了,屏幕就花了,而且,更严重的是 CFrameWnd::OnClose();关闭新建子窗口时这就通不过!!!当然这个错误开始就有跟this->GetDocument()->UpdateAllViews(NULL);这句没关。
而且这个程序在没拆分以前,我调试过,也就是只有新建窗口功能时,没有任何错误!
是不是把因为动态把CMainFrame 拆分了,CFrameWnd::OnClose()就不认他了,导致基类函数不能调用。 void CMainFrame::OnClose()
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
m_nCountWnds--;
CFrameWnd::OnClose(); POSITION pos,pos1;
if(!((CMulFrameApp*)AfxGetApp())->p_ListFrame->IsEmpty())
{
//检索并移走待删除的窗口句柄
for( pos = ((CMulFrameApp*)AfxGetApp())->p_ListFrame->GetHeadPosition(); pos !=NULL;)
{
pos1=pos;
if((((CMulFrameApp*)AfxGetApp())->p_ListFrame->GetNext( pos))==((CMulFrameApp*)AfxGetApp())->m_pMainFrame)
((CMulFrameApp*)AfxGetApp())->p_ListFrame->RemoveAt(pos1);
}
} }
期望在拆分后的各个框内显示的画线程序根本就没丝毫的痕迹。debug跟踪了,画线的那三个视图的已经被创建,也就是他们已经能工作就是没有显示出来,问题究竟出在哪里了呢?是不是在动态创建的窗口的时候关联的视类是CSp2View而不是这三个绘图视类的原因,我准备试一下:(1)在创建的同时就拆分,(2)或者使用另外一个CFrameWnd来作为窗口创建的框架。