博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
文档视图窗口的切换,本人尝试过,有效;
阅读量:5070 次
发布时间:2019-06-12

本文共 3952 字,大约阅读时间需要 13 分钟。

第一,在每个视图列的构造函属性数改为public,同时头文件加上#include <shlwapi.h>;

第二:

在文档的CQiehuanApp里面弄;

1。

.h 文件

private:

UINT m_nCurView;
CView *m_pViews[3];//三个视图,其中一个是本工程的视图类,2个是新建的cformview类;

 

afx_msg void On32772();//要点击切换视图的操作;

afx_msg void On32773();要点击切换视图的操作;

CView* SwitchView( UINT nIndex );
void CreateMoreViews();
BOOL SaveActiveViewsData();

 

2. .cpp 文件

步骤是 创建,保存,切换;

 

在初始化函数的最后,也就是return TRUE 的前面创建文档;

第一步;

BOOL CQiehuanApp::InitInstance()

{

CreateMoreViews();

return TRUE;

}

 

void CQiehuanApp::CreateMoreViews()

{
m_nCurView = 0; // Save index of the currently active view class

// Keep array of views as member of WinApp

CView* pActiveView = ((CFrameWnd*) m_pMainWnd)->GetActiveView();

m_pViews[0] = pActiveView;

m_pViews[1] = (CView*)(new Cmap );//定义一个screenDefineView对象;
m_pViews[2] = ( CView * )new PRODATGA ;

CDocument* pCurrentDoc = ((CFrameWnd*) m_pMainWnd)->GetActiveDocument();

// Initialize a CCreateContext to point to the active document.

// With this context, the new view is added to the document
// when the view is created in CView::OnCreate().
CCreateContext newContext;
newContext.m_pNewViewClass = NULL;
newContext.m_pNewDocTemplate = NULL;
newContext.m_pLastView = NULL;
newContext.m_pCurrentFrame = NULL;
newContext.m_pCurrentDoc = pCurrentDoc;

// The ID of the initial active view is AFX_IDW_PANE_FIRST.

// Incrementing this value by one for additional views works
// in the standard document/view case but the technique cannot
// be extended for the CSplitterWnd case.
CRect rect(0, 0, 0, 0); // gets resized later

// Need to cast pointers to have correct Create functions called

// CForm2 is CFormView::Create
for ( int nView=1; nView <3; nView++ )
{
// Create the new view. In this example, the view persists for
// the life of the application. The application automatically
// deletes the view when the application is closed.
m_pViews[nView]->Create(NULL, NULL,
(AFX_WS_DEFAULT_VIEW & ~WS_VISIBLE),
// views are created with the style of AFX_WS_DEFAULT_VIEW
// In MFC 4.0, this is (WS_BORDER | WS_VISIBLE | WS_CHILD)
rect, m_pMainWnd,
AFX_IDW_PANE_FIRST + nView, &newContext);
m_pViews[nView]->SendMessage( WM_INITIALUPDATE );
}

// When a document template creates a view, the WM_INITIALUPDATE

// message is sent automatically. However, this code must
// explicitly send the message, as follows.

/*** End modification of default InitInstance ***/
}

第二部:

切换,切换函数里面调用保存函数;

afx_msg void On32772();//要点击切换视图的操作;

{  

  SwitchView( 2 );//要切换到第二张视图,第0张视图一般是工程的文档类;

}

afx_msg void On32773();要点击切换视图的操作;

{

  SwitchView( 1 );//要切换到第一张视图,

}

**************

切换功能

 

CView* CQiehuanApp::SwitchView( UINT nIndex )

{
ASSERT( nIndex >=0 && nIndex < 3 );

CView* pNewView = m_pViews[nIndex];

CView* pActiveView =

((CFrameWnd*) m_pMainWnd)->GetActiveView();

if ( !pActiveView ) // No currently active view

return NULL;

if ( pNewView == pActiveView ) // Already there

return pActiveView;

// Update Doc's data if needed

// Don't change view if data validation fails
if ( ! SaveActiveViewsData() )//这里调用了保存的函数;
{
return pActiveView;
}

m_nCurView = nIndex; // Store the new current view's index

// exchange view window ID's so RecalcLayout() works

UINT temp = ::GetWindowLong(pActiveView->m_hWnd, GWL_ID);
::SetWindowLong(pActiveView->m_hWnd, GWL_ID,
::GetWindowLong(pNewView->m_hWnd, GWL_ID));
::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp);

// Display and update the new current view - hide the old one

pActiveView->ShowWindow(SW_HIDE);
pNewView->ShowWindow(SW_SHOW);
((CFrameWnd*) m_pMainWnd)->SetActiveView(pNewView);
((CFrameWnd*) m_pMainWnd)->RecalcLayout();//将Toolbar、DialogBar等可浮动的东西安排位置、处理和View、Frame之间的位置关系的
pNewView->Invalidate();
return pActiveView;
}

保存功能

BOOL CQiehuanApp::SaveActiveViewsData()

{
CView* pActiveView =
((CFrameWnd*) m_pMainWnd)->GetActiveView();

if ( !pActiveView )

return TRUE; // No active view TO save data from, so count as success

return TRUE; // Not a view with data to save!

}

 

 

转载于:https://www.cnblogs.com/chenzuoyou/p/3293079.html

你可能感兴趣的文章
从.NET中委托写法的演变谈开去(上):委托与匿名方法
查看>>
小算法
查看>>
201521123024 《java程序设计》 第12周学习总结
查看>>
新作《ASP.NET MVC 5框架揭秘》正式出版
查看>>
IdentityServer4-用EF配置Client(一)
查看>>
WPF中实现多选ComboBox控件
查看>>
读构建之法第四章第十七章有感
查看>>
Windows Phone开发(4):框架和页 转:http://blog.csdn.net/tcjiaan/article/details/7263146
查看>>
Unity3D研究院之打开Activity与调用JAVA代码传递参数(十八)【转】
查看>>
python asyncio 异步实现mongodb数据转xls文件
查看>>
TestNG入门
查看>>
【ul开发攻略】HTML5/CSS3菜单代码 阴影+发光+圆角
查看>>
[ZJOI2007]棋盘制作 【最大同色矩形】
查看>>
IOS-图片操作集合
查看>>
模板统计LA 4670 Dominating Patterns
查看>>
泛型第23条:请不要在新代码中使用原生态类型
查看>>
团队项目开发客户端——登录子系统的设计
查看>>
【AppScan心得】IBM Rational AppScan 无法记录登录序列
查看>>
简化通知中心的使用
查看>>
IO—》Properties类&序列化流与反序列化流
查看>>