我在设计一个软件,使单文档的程序,主页面显示的是一些画图的曲线(在对话框中固定了,不能改变大小)因此我想通控制按钮,如一个“新增窗口”命令来动态新建一个窗口(目前已经实现)。问题是我想在新建的窗口中实现静态拆分,我将如下代码加入我新建窗口的视类中,执行后没有效果。是不是我用于新建窗口的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;
}

解决方案 »

  1.   

    分割是针对框架窗口的.你可以把相应的函数放到CCHILDFRAME里去.当要动态分态的时候,接到消息以后,让CCHILDFRAME去处理就是了.
      

  2.   

    在末尾加了一条ShowWindow(SW_SHOW),可以看见拆分结果了,但是改变大小时不行,不能正确显示各个窗口的更新内容!
      

  3.   

    我前面说过, 我的程序是单文档程序,没有CHILDFRAME,而这个程序,我是想在动态新生成的窗口里实现拆分,不想把主程序窗口也拆分,请问如果我在CmainFrame里拆分是不是会把主窗口也拆分了?
      

  4.   

    上面少写了一个事情我把最前面的代码改了一句就是把this ,改为this->GetParent(),也就是在框架里面拆分了,然后在末尾加了一条ShowWindow(SW_SHOW),可能是OnDraw的问题,没办法啊,我再试试看了if (!m_wndSplitter.CreateStatic(this->GetParent(),3, 1))
    {
    TRACE0("Failed to CreateStaticSplitter\n");
    return -1;
    }
      

  5.   

    你这也就是把CHILDFRAME分割了.单文档也有一个FRAME对应的.每个视图的更新是要通过Document->UpdateAllView来实现的.视图不会自动更新的.
      

  6.   

    在这句后面加了 this->ShowWindow(SW_SHOW);
    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);
    }
    } }
      

  7.   

    找到毛病了,m_wndSplitter不应该在view类定义,而是作为CmainFrame的成员,通过指针在view对象里面 间接调用。这样在view OnClose的时候就不会出错了。   但是问题还是存在:
       期望在拆分后的各个框内显示的画线程序根本就没丝毫的痕迹。debug跟踪了,画线的那三个视图的已经被创建,也就是他们已经能工作就是没有显示出来,问题究竟出在哪里了呢?是不是在动态创建的窗口的时候关联的视类是CSp2View而不是这三个绘图视类的原因,我准备试一下:(1)在创建的同时就拆分,(2)或者使用另外一个CFrameWnd来作为窗口创建的框架。