栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

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

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

先来张图片

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;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/65098.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号