在对话框(CDialog)中使用分割窗(CSplitterWnd)

原文见:

http://www.codeguru.com/cpp/w-d/splitter/tutorials/article.php/c4705

 

例子 

 

可以使用以下三个步骤在对话框中创建分割窗:

1. In the OnCreate function or your CDialog, register a new WindowClass by calling "AfxRegisterWndClass".

    在你的CDialog类的OnCreate函数中使用AfxRegisterWndClass注册一个新的窗口类。

2. Create a new CFrameWnd by using the "new" operator and initialize it.

    使用new操作符创建一个CFrameWnd,并对其进行初始化。

3. Create your splitter by using the new CFrameWnd you just created as the parent.

    在步骤2中创建的CFrameWnd上创建分割窗。

 

 

主要代码:

  1. int CMyDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
  2. {
  3.     if (CDialog::OnCreate(lpCreateStruct) == -1)
  4.       return -1;
  5.     // Initialize a context for the view. CMyTreeView is my view and
  6.     // is defined as :  class CMyTreeView : public CTreeView.
  7.     CCreateContext ccc;
  8.     ccc.m_pNewViewClass      = RUNTIME_CLASS(CMyTreeView);
  9.     ccc.m_pCurrentDoc           = NULL;
  10.     ccc.m_pNewDocTemplate = NULL;
  11.     ccc.m_pLastView              = NULL;
  12.     ccc.m_pCurrentFrame       = NULL;
  13.     // Because the CFrameWnd needs a window class, we will create
  14.     // a new one. I just copied the sample from MSDN Help.
  15.     // When using it in your project, you may keep CS_VREDRAW and
  16.     // CS_HREDRAW and then throw the other three parameters.
  17.     CString strMyClass = AfxRegisterWndClass(CS_VREDRAW |
  18.                          CS_HREDRAW,
  19.                          ::LoadCursor(NULL, IDC_ARROW),
  20.                          (HBRUSH) ::GetStockObject(WHITE_BRUSH),
  21.                          ::LoadIcon(NULL, IDI_APPLICATION));
  22.     // Create the frame window with "this" as the parent
  23.     m_pMyFrame = new CFrameWnd;
  24.     m_pMyFrame->Create(strMyClass,"", WS_CHILD,
  25.                                          CRect(0,0,1,1), this);
  26.     m_pMyFrame->ShowWindow(SW_SHOW);
  27.     m_pMyFrame->MoveWindow(0,0,300,300);
  28.     // and finally, create the splitter with the frame as
  29.     // the parent
  30.     m_wndSplitter.CreateStatic(pMyFrame,1, 2);
  31.     m_wndSplitter.CreateView(0,0, RUNTIME_CLASS(CMyTreeView),
  32.                                                CSize(100,100), &ccc);
  33.     m_wndSplitter.CreateView(0,1, RUNTIME_CLASS(CMyTreeView),
  34.                                                CSize(100,100), &ccc);
  35. }
  36. BOOL CMyDialog::OnInitDialog()
  37. {
  38.   CDialog::OnInitDialog();
  39.   CRect rect;
  40.   // Get the rectangle of the custom window. The custom window
  41.   // is just a a big button that is not visible and is disabled.
  42.   // It's a trick to not use coordinates directly.
  43.   GetDlgItem(IDC_CUTSOM_WINDOW)->GetWindowRect(&rect);
  44.   // Move the splitter
  45.   ScreenToClient(&rect);
  46.   m_pFrameWnd->MoveWindow(&rect);
  47.   m_pFrameWnd->ShowWindow(SW_SHOW);
  48.   m_wndSplitter.MoveWindow(0,0, rect.Width(), rect.Height());
  49.   m_wndSplitter.ShowWindow(SW_SHOW);
  50.   return TRUE;  // return TRUE unless you set the focus to a
  51.                 // control
  52.                 // EXCEPTION: OCX Property Pages should return
  53.                 // FALSE
  54. }
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值