博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++ VC实现对话框窗口任意分割
阅读量:7030 次
发布时间:2019-06-28

本文共 1665 字,大约阅读时间需要 5 分钟。

    最近写MFC的程序,想在对话框里实现窗口的任意分割。现在网络资料一大抄,找个东西实在麻烦。总算这个很简单,很快就搞定了,写下来做个笔记。

    个人认为简单问题最好就是直接贴源代码,一看就明白,说来说去反而弄不清楚,那我就少废话了,自己看吧,注释很清楚。

先来张图片

1. 新建一个MFC对话框程序MySplitterDlg。 再插入两个Dialog资源 ,这里一定要选择IDD_FORMVIEW类别的对话框,分别新建类CMyFormView0 和CMyFormView1,基类别选CDialog,一定要选择CFormView。

2. CMySplitterDlg中增加WM_CREATE的消息响应,编辑OnCreate()

int CMySplitterDlg::OnCreate(LPCREATESTRUCT lpCreateStruct){    if (CDialog::OnCreate(lpCreateStruct) == -1)        return -1;    // Because the CFRameWnd needs a window class, we will create a new one. I just copied the sample from MSDN Help.    // When using it in your project, you may keep CS_VREDRAW and CS_HREDRAW and then throw the other three parameters.    //需要注册窗口类    CString strMyClass = AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW,                     ::LoadCursor(NULL, IDC_ARROW),    (HBRUSH) ::GetStockObject(WHITE_BRUSH),                     ::LoadIcon(NULL, IDI_APPLICATION));    // Create the frame window with "this" as the parent    m_pMyFrame = new CFrameWnd;    m_pMyFrame->Create(strMyClass,"", WS_CHILD,   CRect(0,0,300,300), this);    m_pMyFrame->ShowWindow(SW_SHOW);    // and finally, create the splitter with the frame as the parent    m_cSplitter.CreateStatic(m_pMyFrame,1, 2); //在Frame里切分视图窗口为1×2,就是一行两列    m_cSplitter.CreateView(0,0, RUNTIME_CLASS(CMyFormView0),   CSize(100,100), NULL);//第一行一列    m_cSplitter.CreateView(0,1, RUNTIME_CLASS(CMyFormView1), CSize(100,100), NULL);//第一行二列     return 0;}

3. 在CMySplitterDlg::OnInitDialog()中显示Frame

int CMySplitterDlg::OnInitDialog(){CDialog::OnInitDialog();GetWindowRect(&cRect);ScreenToClient(&cRect);m_pMyFrame->MoveWindow(&cRect);m_pMyFrame->ShowWindow(SW_SHOW);return TRUE;}

转载地址:http://prrxl.baihongyu.com/

你可能感兴趣的文章
HDU 1205
查看>>
Openstack-L 路由注入方式
查看>>
利用ROS工具从bag文件中提取图片
查看>>
Java常用类库
查看>>
Android开发之Activity转场动画
查看>>
List集合三种遍历方法
查看>>
【译】OpenDaylight控制器:YANG Schema和Model
查看>>
C#访问修饰符(public,private,protected,internal,sealed,abstract)
查看>>
android消息线程和消息队列
查看>>
EXCEL中计算不重复单元格的个数
查看>>
二层设备与三层设备的区别--总结
查看>>
安装pytorch成功但cuda不可用
查看>>
unity__DrawCall的理解
查看>>
springboot架构下运用shiro后在configuration,通过@Value获取不到值,总是为null
查看>>
SQLServer 数据库镜像+复制切换方案
查看>>
Postman初探
查看>>
仿淘宝头像上传功能(一)——前端篇。
查看>>
Eclipse通过集成svn实现版本控制
查看>>
OS开发过程中常用开源库
查看>>
关于在多个UItextield切换焦点
查看>>