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

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

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上创建分割窗。

int CMyDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{ 
    if (CDialog::OnCreate(lpCreateStruct) == -1) 
      return -1; 

    // Initialize a context for the view. CMyTreeView is my view and 
    // is defined as :  class CMyTreeView : public CTreeView. 
    CCreateContext ccc; 
    ccc.m_pNewViewClass      = RUNTIME_CLASS(CMyTreeView); 
    ccc.m_pCurrentDoc           = NULL; 
    ccc.m_pNewDocTemplate = NULL; 
    ccc.m_pLastView              = NULL; 
    ccc.m_pCurrentFrame       = NULL; 

    // 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,1,1), this); 
    m_pMyFrame->ShowWindow(SW_SHOW); 
    m_pMyFrame->MoveWindow(0,0,300,300); 

    // and finally, create the splitter with the frame as 
    // the parent 
    m_wndSplitter.CreateStatic(pMyFrame,1, 2); 
    m_wndSplitter.CreateView(0,0, RUNTIME_CLASS(CMyTreeView), 
                                               CSize(100,100), &ccc); 
    m_wndSplitter.CreateView(0,1, RUNTIME_CLASS(CMyTreeView), 
                                               CSize(100,100), &ccc); 
} 

BOOL CMyDialog::OnInitDialog() 
{ 
  CDialog::OnInitDialog(); 
  CRect rect; 

  // Get the rectangle of the custom window. The custom window 
  // is just a a big button that is not visible and is disabled. 
  // It's a trick to not use coordinates directly. 
  GetDlgItem(IDC_CUTSOM_WINDOW)->GetWindowRect(&rect); 

  // Move the splitter 
  ScreenToClient(&rect); 
  m_pFrameWnd->MoveWindow(&rect); 
  m_pFrameWnd->ShowWindow(SW_SHOW); 
  m_wndSplitter.MoveWindow(0,0, rect.Width(), rect.Height()); 
  m_wndSplitter.ShowWindow(SW_SHOW); 

  return TRUE;  // return TRUE unless you set the focus to a 
                // control 
                // EXCEPTION: OCX Property Pages should return 
                // FALSE 
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值