mfc 单文档分拆窗口

来源:互联网 发布:雨花区网络问政 编辑:程序博客网 时间:2024/05/23 19:14
  1. 在CMainFrame中定义CSplitterWnd类型的成员变量:

class CMainFrame : public CFrameWnd
{    

protected: // 仅从序列化创建
    CMainFrame();
    DECLARE_DYNCREATE(CMainFrame)

// 属性
public:
    CSplitterWnd m_wndSplitter;

    ……

}

       2 .  重载CMainFrame的OnCreateClient函数:

             BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
             {
                // TODO: 在此添加专用代码和/或调用基类
                CRect rect;

                GetClientRect(&rect);
                m_wndSplitter.CreateStatic(this, 1, 2);
                m_wndSplitter.CreateView(0, 0, pContext->m_pNewViewClass, CSize(1000, 0), pContext);
                m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CNewView), CSize(0, 0), pContext);
                m_wndSplitter.SetActivePane(0, 0);

                return TRUE;
             }

             CNewView是拆分出来的新窗口中的视图类。



MFC单文档 窗口分割(二次分割)  

2009-05-19 09:52:47|  分类: vc开发资料整理|字号 订阅

文件1   

class CMainFrame : public CFrameWnd 添加如下代码

public:
CSplitterWnd m_splMainCols;
CSplitterWnd m_splRightRows;
BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);

cpp文件添加函数

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
if(!m_splMainCols.CreateStatic(this, 1, 3))
{
   return FALSE;
}
if(!m_splMainCols.CreateView(0, 0, RUNTIME_CLASS(CLeftView), CSize(100, 0), pContext))
{
   return FALSE;
}
/*
if(!m_splMainCols.CreateView(0, 1, RUNTIME_CLASS(CLeftView), CSize(500, 0),pContext))
{
   return FALSE;
}
*/
if(!m_splMainCols.CreateView(0, 2, RUNTIME_CLASS(CLeftView), CSize(0, 0),pContext))
{
   return FALSE;
}

if(!m_splRightRows.CreateStatic(&m_splMainCols, 2, 1, WS_CHILD|WS_VISIBLE, m_splMainCols.IdFromRowCol(0,1) ))
{
   return FALSE;
}
if(!m_splRightRows.CreateView(0, 0, RUNTIME_CLASS(CLeftView), CSize(0, 300), pContext))
{
   return FALSE;
}
if(!m_splRightRows.CreateView(1, 0, RUNTIME_CLASS(CLeftView), CSize(0, 0), pContext))
{
   return FALSE;
}

//m_splMainCols.SetRowInfo(0, 350, 0); //重新设置行宽
    //m_splMainCols.RecalcLayout();

//m_splMainCols.SetColumnInfo(2,100,50);
return TRUE;
}

界面预览:

  MFC单文档 窗口分割(二次分割) - 涛涛 - 小小程序员的梦想

原创粉丝点击