Provide an Alternative View to Data Using Splitter Window (轉)
HOWTO: Prov an Alternative View to Data Using Splitter Window (Q196832)
The information in this article applies to:
- The 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 . 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 with different numbers of panes, depending on some run-time conditions.
Steps to Create Sample
- Create a new SDI project.
- Add a SplitterWnd (ID_VIEW_SPLITTERWND) menu item to a View menu. This item turns the splitter window on and off.
- 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; }
- To avoid re 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(); }
- Add a pointer to a CSplitterWnd in the CMainFrame definition:
class CMainFrame : public CFrameWnd { ... protected: CSplitterWnd *m_pSplitter; ... };
- 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; }
- Add two new CView-derived classes to your project, representing views that are the panes in your CSplitterWnd.
- Add the following #include statements in your MainFrm.cpp file:
#include "MyDoc.h" #include "MyView.h" #include "Pane1View.h" #include "Pane2View.h"
- 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 s Keywords kbDocView kbMFC KbUIDesign kbVC420 kbVC500 kbVC600 kbGrpDSMFCATL
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752019/viewspace-977821/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- whose view is not in the window hierarchy!View
- Step by Step Data Replication Using Oracle GoldenGateOracleGo
- PostgreSQL DBA(181) - Using PostgreSQL as a Data WarehouseSQL
- 【譯】Using .NET for Apache Spark to Analyze Log DataApacheSpark
- Window、WindowManager、View 之間的關係View
- LangChain AlternativeLangChain
- Android自定義View之Window、ViewRootImpl和View的三大流程AndroidView
- Activity、View、Window之間關係的分析View
- How To Replicate Data from Oracle to Postgres Using GoldenGate (Doc ID 1544137.1OracleGo
- provide/injectIDE
- 底層剖析 Window 、Activity、 View 三者關係View
- Guava字串處理Joiner、SplitterGuava字串
- Guava中的Joiner和SplitterGuava
- 論文學習筆記 - Classifification of Hyperspectral and LiDAR Data Using Coupled CNNs筆記CNN
- [轉帖]10 Tips for using the Eclipse Memory AnalyzerEclipse
- django rest django.core.exceptions.ImproperlyConfigured: Could not resolve URL for hyperlinked relationship using view nameDjangoRESTExceptionView
- SSL - SSLHandshakeException: No subject alternative names presentException
- (xml中sql語句為紅)解決No data sources are configured to run this SQL and provide advanced的問題XMLSQLIDE
- 豆瓣讀書搜尋頁的window.__DATA__的解密解密
- window history pushState replaceState 跳轉原理
- Please provide a valid cache pathIDE
- 元件通訊 provide inject元件IDE
- [Vue] Provide and Inject Global StorageVueIDE
- 圖解Android - Android GUI 系統 (2) - 視窗管理 (View, Canvas, Window Manager)圖解AndroidGUIViewCanvas
- 前端效能監控-window.performance(轉)前端ORM
- Android把一個View轉成Bitmap+處理帶圓角View轉化後黑邊AndroidView
- Wilcoxon秩和檢驗的statistic和alternative
- Dynamics 365 Web API Set Values of all Data Types using Web API in Dynamics CRM Through C#WebAPIC#
- Oracle 查詢轉換-02 View MergingOracleView
- oracle data Format Models---二(轉)OracleORM
- Embracing Domain Differences in Fake News- Cross-domain Fake News Detection using Multimodal Data(AAAI21)AIROS
- SSL - SSLHandshakeException: No subject alternative names matching IP address foundException
- 元件間通訊provide和inject元件IDE
- MySQL 索引優化 Using where, Using filesortMySql索引優化
- window caps 轉換成 ctrl 按鍵對映
- MySQL explain結果Extra中"Using Index"與"Using where; Using index"區別MySqlAIIndex
- 【文獻閱讀】ES as a Scalable Alternative to RL(OpenAI 17)OpenAI
- Keil MDK中的Code, RO-data , RW-data, ZI-data分別代表什麼意思?(轉)
- PDF Merge PDF Splitter for Mac(PDF合併和拆分軟體)Mac