MFC MDI 程序中拆分子窗口

发布于 2024-10-27 19:53:36 字数 674 浏览 1 评论 0原文

我正在尝试拆分我正在开发的 MFC MDI 程序的子窗口,但遇到了一些问题。我知道我必须使用 CSplitterWnd 类,并且一直在尝试按照此处帖子上的说明进行操作:

使用 CSplitterWnd 在 CChildFrame 中创建多个视图

,但似乎无法使其工作,任何人都可以为我提供有关这些说明的一些建议,我有一些具体问题:

  1. CRightView 是否也是 CView 派生类以及其中应包含哪些代码(如果有)?

  2. m_pLeftView、m_pRightView、m_pPhongView 和 m_pPhongInfo 是否都是相应类的变量,它们是否具有任何特定类型?

    m_pLeftView、
  3. CTreeView从哪里来,好像不是标准基类?

  4. CChildFrame::OnCreateClient 中的 rc.Width 给出了未声明的标识符错误,我是否应该在此处声明一些内容?

我很感激任何关于这方面的建议,真的很努力让分离器工作。

谢谢

I am trying to split the Child Window of an MFC MDI progarm that I am working on but am having some problems. I know I have to use the CSplitterWnd class and have been trying to follow the instructions on the post here:

Create multi views in a CChildFrame using CSplitterWnd

but can't seem to get it to work, would anyone be able to offer me some advice with regard to these instructions, I have some specific questions:

  1. Is CRightView also a CView derived class and what code should go in there if any?

  2. Are m_pLeftView, m_pRightView, m_pPhongView and m_pPhongInfo all variables of the appropriate classes and do they have any particular type?

  3. Where does CTreeView come from, does not seem to be a standard base class?

  4. rc.Width in CChildFrame::OnCreateClient gives an undeclared identifier error, is there something I should be declaring somewhere here?

I would appreciate any advice about this, really struggling to get the splitter to work.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮色兮凉城 2024-11-03 19:53:36

经过几天的努力,我成功解决了自己的问题,我在这里为可能遇到同样问题的其他人添加解决方案。

  1. 声明两个视图类,在我的例子中,CElement View 是一个 CWnd 派生类,CSampleViewer3dView 是一个 CView 派生类。

  2. CChildFrame中添加一个具有私有访问权限的变量,输入CSplitterWnd并命名为m_wndSplitter

  3. CChildFrame中添加对OnCreateClient函数的覆盖,这应该添加代码:

     virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
    

到ChildFrm.h,您还应该向ChildFrm.h添加一个布尔标志m_bInitSplitter:

    BOOL m_bInitSplitter;

您还必须添加:

m_bInitSplitter = false;

在ChildFrm.cpp的构造函数中,当您使用向导添加变量时,将以下代码添加到ChildFrm.cpp中:

    BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)
    {
    }
  1. 将以下代码放入CChildFrame::OnCreateClient:

     BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)  
     {  
         C矩形cr;  
         GetWindowRect( &cr );  
    
         if (!m_wndSplitter.CreateStatic(this, 1, 2))   
         {   
             MessageBox("设置分割框时出错!", "初始化错误!", MB_OK | MB_ICONERROR);   
             返回假;   
         }  
    
         if (!m_wndSplitter.CreateView( 0, 0, RUNTIME_CLASS(CElementView), 
     CSize(cr.Width()/2, cr.Height()), pContext ) )   
         {   
             MessageBox("设置分割框时出错!", "初始化错误!", MB_OK | MB_ICONERROR);  
             返回假;   
         }  
    
         if (!m_wndSplitter.CreateView( 0, 1, RUNTIME_CLASS(CSampleViewer3dView), 
     CSize(cr.Width()/2, cr.Height()), pContext))   
         {    
             MessageBox("设置分割框时出错!", "初始化错误!", MB_OK | MB_ICONERROR);  
         返回假;   
         }  
         m_bInitSplitter = TRUE;  
    
         返回真;  
     }  
    
  2. WM_SIZE 消息的覆盖添加到 CChildFrame 并插入以下代码:

     void CChildFrame::OnSize(UINT nType, int cx, int cy)  
     {  
         CMDIChildWnd::OnSize(nType, cx, cy);  
         C矩形cr;  
         GetWindowRect(&cr);  
    
         if (m_bInitSplitter && nType != SIZE_MINIMIZED)  
         {  
             m_wndSplitter.SetRowInfo( 0, cy, 0 );  
             m_wndSplitter.SetColumnInfo(0, cr.Width()*0.25 / 2, 50);  
             m_wndSplitter.SetColumnInfo(1, cr.Width()*0.75 / 2, 50);  
    
             m_wndSplitter.RecalcLayout();  
         }  
     } 
    

您可以通过将 0.25 和 0.75 的值更改为所需的百分比来编辑每个窗口的大小。您希望每个视图占据的屏幕。

  1. 将两个视图的头文件添加到ChildFrm.cpp,例如ElementView.hSampleViewer3dView.h

然后,您应该在 MDI 程序的子窗口中拥有两个独立的视图。

After working on it for a couple of days I've managed to solve my own problem, I'm adding the solution here for anyone else who might have the same problem.

  1. Declare the two view classes, in my case CElement View which is a CWnd derived class and CSampleViewer3dView which is a CView derived class.

  2. In CChildFrame add a variable with access private, type CSplitterWnd and name m_wndSplitter.

  3. Add an override for the OnCreateClient function in CChildFrame, this should add the code:

     virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
    

to ChildFrm.h, you should also add a boolean flag m_bInitSplitter to ChildFrm.h:

    BOOL m_bInitSplitter;

you also have to add:

m_bInitSplitter = false;

to the constructor of ChildFrm.cpp, the following code is added to ChildFrm.cpp when you add the variable using the wizard:

    BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)
    {
    }
  1. Put the following code into CChildFrame::OnCreateClient:

     BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)  
     {  
         CRect cr;  
         GetWindowRect( &cr );  
    
         if (!m_wndSplitter.CreateStatic(this, 1, 2))   
         {   
             MessageBox("Error setting up splitter frames!", "Init Error!", MB_OK | MB_ICONERROR);   
             return FALSE;   
         }  
    
         if (!m_wndSplitter.CreateView( 0, 0, RUNTIME_CLASS(CElementView), 
     CSize(cr.Width()/2, cr.Height()), pContext ) )   
         {   
             MessageBox("Error setting up splitter frames!", "Init Error!", MB_OK | MB_ICONERROR);  
             return FALSE;   
         }  
    
         if (!m_wndSplitter.CreateView( 0, 1, RUNTIME_CLASS(CSampleViewer3dView), 
     CSize(cr.Width()/2, cr.Height()), pContext))   
         {    
             MessageBox("Error setting up splitter frames!", "Init Error!", MB_OK | MB_ICONERROR);  
         return FALSE;   
         }  
         m_bInitSplitter = TRUE;  
    
         return TRUE;  
     }  
    
  2. Add an override for the WM_SIZE message to CChildFrame and insert the following code:

     void CChildFrame::OnSize(UINT nType, int cx, int cy)  
     {  
         CMDIChildWnd::OnSize(nType, cx, cy);  
         CRect cr;  
         GetWindowRect(&cr);  
    
         if (m_bInitSplitter && nType != SIZE_MINIMIZED)  
         {  
             m_wndSplitter.SetRowInfo( 0, cy, 0 );  
             m_wndSplitter.SetColumnInfo(0, cr.Width()*0.25 / 2, 50);  
             m_wndSplitter.SetColumnInfo(1, cr.Width()*0.75 / 2, 50);  
    
             m_wndSplitter.RecalcLayout();  
         }  
     } 
    

You can edit the size of each window by changing the values of 0.25 and 0.75 to the required percentage of the screen that you want each view to take up.

  1. Add header files for the two views to ChildFrm.cpp, e.g. ElementView.h and SampleViewer3dView.h.

You should then have two independent views in the child window of an MDI program.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文