• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++VC实现对话框窗口任意分割

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

    最近写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;
}

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++调用Python脚本发布时间:2022-07-13
下一篇:
c++STL之常用集合算法发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap