分享
 
 
 

Provide an Alternative View to Data Using Splitter Window

王朝vc·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

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

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

}

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 Words

Keywords

kbDocView kbMFC KbUIDesign kbVC420 kbVC500 kbVC600 kbGrpDSMFCATL

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有