C++ MFC 创建MDI动态多文档

1 新建mfc mdi程序MDIFormViewTest,选择view 的基类为CFormView

2 添加FormView对话框资源

3 双击对话框资源为其添加类CFormView2,选择基类为CFormView

4 为CMainFrame添加成员变量并添加引用

CChildFrame* m_pFormView;
#include "ChildFrm.h"

 

5 修改CMainFrame的OnCreate方法

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("未能创建工具栏\n");
		return -1;      // 未能创建
	}

	if (!m_wndStatusBar.Create(this))
	{
		TRACE0("未能创建状态栏\n");
		return -1;      // 未能创建
	}
	m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));

	// TODO: 如果不需要可停靠工具栏,则删除这三行
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);

	m_pFormView->LoadFrame(IDR_MDIFormViewTestTYPE, WS_OVERLAPPED | FWS_ADDTOTITLE, this, NULL);
	CCreateContext context;
	context.m_pNewViewClass = RUNTIME_CLASS(CFormView2);
	context.m_pCurrentDoc = NULL;
	m_pFormView->CreateView(&context);
	m_pFormView->ShowWindow(SW_SHOW);


	return 0;
}

6 运行

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值