使用CSplitterWnd切分窗口

本文介绍了使用MFC的CSplitterWnd类进行窗口切分的方法。通过具体代码示例展示了如何创建静态切分窗口,并在不同区域显示不同的视图内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 我们在开发程序的时候,经常需要切分窗口。现在介绍一种方法:使用MFC的CSplitterWnd类切分窗口以抛出石头引出玉来。
在MainFrame.h
protected: 
 CSplitterWnd m_splitter;  //引入 CSplitterWnd类
#include "afxext.h"               //CEditView类所需要的头文件.

在MainFrame.cpp 文件中
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
 // TODO: Add your specialized code here and/or call the base class

 if (!m_splitter.CreateStatic(this,1,2))
 {
  return false;
 }

 CRect rect;
 GetClientRect(&rect);
 m_splitter.CreateView(0,1,RUNTIME_CLASS(CSingleDocTestView),CSize(rect.Width()-rect.Width()/4,rect.Height()),pContext);

 m_splitter.CreateView(0,0,RUNTIME_CLASS(CMyEditView),CSize(rect.Width()/4,rect.Height()),pContext);
 return TRUE;
// return CFrameWnd::OnCreateClient(lpcs, pContext); //这个要注销掉,替换掉 return TRUE;
}
创建一个CEditView类的派生类
class CMyEditView : public CEditView
{
}
在 SingleDocView.cpp中.
void CSingleDocTestView::OnSize(UINT nType, int cx, int cy)
{
 CView::OnSize(nType, cx, cy);
 
 // TODO: Add your message handler code here
 CRect rect;
 GetClientRect(&rect);
 if (m_Testdlg.m_hWnd)
 {
  m_Testdlg.MoveWindow(&rect);
 }
}

void CSingleDocTestView::OnInitialUpdate()
{
 CView::OnInitialUpdate();
 
 // TODO: Add your specialized code here and/or call the base class
 m_Testdlg.Create(IDD_TESTDIALOG,this);
 m_Testdlg.ShowWindow(SW_SHOW);

 CRect rect;
 GetClientRect(&rect);
 if (m_Testdlg.m_hWnd)
 {
  m_Testdlg.MoveWindow(&rect);
 }
}
创建一个 窗体对话框
 CTestDlg m_Testdlg;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值