MFC CSplitterWnd 静态分割窗口

首先建立MFC AppWizard(exe),取名字为SplitterWnd,下一步,选择单文档“Single document”,其他默认,点击“完成”。

点击ResourceView,在Dialog下插入两个个Dialog窗口用于稍后的分割后的窗口,ID号分别改为“IDD_FORMVIEW1”和“IDD_FORMVIEW2”。记得及时保存。

单击ClassView标签,添加2个类,当然也可以从ClassWizard中添加,名字叫FormView1,类选择CFormView,Dialog ID选择IDD_FORMVIEW1,另一个类叫FormView2,ID选择IDD_FORMVIEW2。

在CMainFrame中添加两个成员变量,类型都为CSplitterWnd,变量名分别为m_splitter和m_splitter1,然后添加一个虚函数OnCreateClient,点击编辑代码,将如下代码更改

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
    // TODO: Add your specialized code here and/or call the base class
    return CFrameWnd::OnCreateClient(lpcs, pContext);
}

改为

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{

    //创建一个静态分栏窗口,分为一行二列 
    if(m_splitter.CreateStatic(this,1,2)==NULL) 
        return FALSE;

    //将CCSplitterWndView连接到0行0列窗格上
    m_splitter.CreateView(0,0,RUNTIME_CLASS(CSplitterWndView),CSize(600,600), pContext);

    if(m_splitter1.CreateStatic(&m_splitter,2,1,WS_CHILD|WS_VISIBLE, 
        m_splitter.IdFromRowCol(0, 1))==NULL) 
        return FALSE; //将第0行1列再分开2行1列 
    //将FormView1类连接到第二个分栏对象的0行0列
    m_splitter1.CreateView(0,0,RUNTIME_CLASS(FormView1),CSize(200,400),pContext); 
    //将FormView2类连接到第二个分栏对象的1行0列
    m_splitter1.CreateView(1,0,RUNTIME_CLASS(FormView2),CSize(200,200),pContext); 
    return TRUE;

}

 

添加头文件

#include "SplitterWndDoc.h"
#include "SplitterWndView.h"
#include "FormView1.h"
#include "FormView2.h"

好了,现在编译运行,可以得到分栏的结果了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值