• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

Provide an Alternative View to Data Using Splitter Window

发布: 2007-7-01 20:40 | 作者: admin | 来源: | 查看: 11次 | 进入软件测试论坛讨论

领测软件测试网

HOWTO: Provide an Alternative View to Data Using Splitter Window (Q196832)


The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), used with:
    • Microsoft Visual C++, 32-bit Enterprise Edition, version 4.2
    • Microsoft Visual C++, 32-bit Professional Edition, version 4.2
    • Microsoft Visual C++, 32-bit Enterprise Edition, version 5.0
    • Microsoft Visual C++, 32-bit Professional Edition, version 5.0
    • Microsoft Visual C++, 32-bit Enterprise Edition, version 6.0
    • Microsoft Visual C++, 32-bit Professional Edition, version 6.0
    • Microsoft Visual C++, 32-bit Learning Edition, version 6.0



SUMMARY

This article demonstrates how to use a static splitter window in a traditional SDI document-view architecture. The article shows how to design an application that can switch between a single view and a splitter window that can embed as many panes as necessary.


MORE INFORMATION

The solution consists of embedding a pointer to a CSplitterWnd in CMainFrame, as opposed to the recommended way of embedding the CSplitterWnd object. Later, when the application needs to switch from the regular view to the splitter window, this splitter window is created on the heap and initialized by using CreateStatic(), while the regular view is destroyed.

NOTE: To avoid destruction of the CDocument-derived object when the view is destroyed, you need to set its m_bAutoDelete data member to FALSE.

You can easily expand the code to support static splitter windows with different numbers of panes, depending on some run-time conditions.

Steps to Create Sample

  1. Create a new SDI project.

  2. Add a SplitterWnd (ID_VIEW_SPLITTERWND) menu item to a View menu. This item turns the splitter window on and off.

  3. To preserve the document when there is no view associated with it, add add the following code in the CDocument-derived class constructor:

          CMyDoc::CMyDoc()
          {
             m_bAutoDelete = FALSE;
          }
    
  4. To avoid resource leaks, you also need to set the flag back to true before the destruction of the last view associated with the document (for example, in the CMainFrame handler of WM_CLOSE:

    CMainFrame::OnClose()):
          CMainFrame::OnClose()
          {
             GetActiveDocument()->m_bAutoDelete = TRUE;
             CFrameWnd::OnClose();
          }
    
  5. Add a pointer to a CSplitterWnd in the CMainFrame definition:

          class CMainFrame : public CFrameWnd
          {
          ...
            protected:
             CSplitterWnd *m_pSplitter;
          ...
          };
    
  6. Initialize this object in the CMainFrame constructor, and delete it in the destructor:

          CMainFrame::CMainFrame()
          {
             // TODO: add member initialization code here.
             m_pSplitter = NULL;
          }
    
          CMainFrame::~CMainFrame()
          {
             if (m_pSplitter)
                delete m_pSplitter;
          }
    
  7. Add two new CView-derived classes to your project, representing views that are the panes in your CSplitterWnd.

  8. Add the following #include statements in your MainFrm.cpp file:

          #include "MyDoc.h"
          #include "MyView.h"
          #include "Pane1View.h"
          #include "Pane2View.h"
    
  9. Use Class Wizard to create a command and an UpdateUI handler in CMainFrame for the menu item you added:

          void CMainFrame::OnUpdateViewSplitterWnd(CCmdUI* pCmdUI)
          {
             // TODO: Add your command update UI handler code here.
             pCmdUI->SetCheck(m_pSplitter!=NULL);
          }
    
          void CMainFrame::OnViewSplitterWnd()
          {
             // TODO: Add your command handler code here.
             CCreateContext ctx;
             ctx.m_pNewViewClass = RUNTIME_CLASS(CMyView);
             // GetActiveDocument() call before you destroy m_splitter.
             ctx.m_pCurrentDoc = GetActiveDocument();
             ASSERT(ctx.m_pCurrentDoc!=NULL);
    
             // m_pSplitter !=NULL when there is a visible splitter.
             if (m_pSplitter)
             {
                // Destroy splitter window.
                delete m_pSplitter;
                m_pSplitter = NULL;
    
                // Create and initialize CMyView.
                SetActiveView((CView*)CreateView(&ctx));
                GetActiveView()->OnInitialUpdate();
             }
             else
             {
                // Destroy CMyView.
                GetActiveView()->DestroyWindow();
    
                // Create new splitter window.
                m_pSplitter = new CSplitterWnd;
                if (!m_pSplitter->CreateStatic(this, 1, 2))
                {
                   TRACE0("Can´t create splitter window.\n");
                   return;
                }
                else
                {
                   if ((!m_pSplitter->CreateView(0, 0,
                                                 RUNTIME_CLASS(CPane1View),
                                                 CSize(200, 0), &ctx))
                     ||(!m_pSplitter->CreateView(0, 1,
                                                 RUNTIME_CLASS(CPane2View),
                                                 CSize(500, 0), &ctx)))
                   {
                      TRACE0("Can´t create one of the splitter panes.\n");
                      return;
                   }
    
                   // Initialize the two panes (each containing a view
                   // associated with the current document).
                   ((CView*)m_pSplitter->GetPane(0, 0))->OnInitialUpdate();
                   ((CView*)m_pSplitter->GetPane(0, 1))->OnInitialUpdate();
                   SetActiveView((CView*)m_pSplitter->GetPane(0, 0));
                }
             }
    
             // Redisplay frame.
             RecalcLayout();
         
     }
    


Published Dec 8 1998 9:32PM Issue Type kbhowto
Last Modifed Jul 17 2001 4:32PM Additional Query Words
Keywords kbDocView kbMFC KbUIDesign kbVC420 kbVC500 kbVC600 kbGrpDSMFCATL

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网