设为首页  
联系我们  
加入收藏  
网页制作 冲浪宝典 图形图像 操作系统 软件教学 编程开发 认证考试 安全技术 站长专区 文学驿站 娱乐天地 游戏天地 办公软件
文章搜索
您的位置: 首页 >> 文章首页 >> 编程开发 >> Visual C++ >> Provide an Alternative View to Data Using Splitter Window
精品推荐
Visual C++点击TOP10
·用WINSOCK实现聊天室的VC++程序设计
·利用mfc编写activex控件
·用vc实现生产者消费者问题
·DirectX8.0
·C/C++ 大量经典编程书籍下载
·VC快捷键大全
·CreateFileMapping的MSDN翻译和使用心得
·Windows环境下的麦克风录音系统
·挂钩Windows API
·如何开发OPC Server
编程开发点击TOP10
·数字小键盘指法练习
·用C语言编通讯录程序(初学者级别的)
·ASP.NET 程序中常用的三十三种代码
·我写的Java学生成绩管理系统源代码
·CHK文件恢复工具
·java笔试题
·Modem 常用AT指令集
·异常java.sql.SQLException: Io exception:The Network Adapter could not establish connection
·单片机模拟I2C总线及24C02(I2C EEPROM)读写实例(源代码)
·C++经典电子书下载
精选专题

Provide an Alternative View to Data Using Splitter Window

作者: 来源:网络文章 时间:2005-12-13 18:12:35

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


PublishedDec 8 1998 9:32PM Issue Typekbhowto
Last ModifedJul 17 2001 4:32PM Additional Query Words
KeywordskbDocView kbMFC KbUIDesign kbVC420 kbVC500 kbVC600 kbGrpDSMFCATL

Provide an Alternative View to Data Using Splitter Window 相关文章:
Provide an Alternative View to Data Using Splitter Window 相关软件:
特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
转载请注明来源:http://www.xgdown.com