#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <afxtempl.h>
class CMainFrame : public CFrameWnd
{
	
protected: // create from serialization only
	CMainFrame();
	DECLARE_DYNCREATE(CMainFrame)

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMainFrame)
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CMainFrame();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
	virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs,CCreateContext* pContext );
	int		AddView(CCreateContext *pContext);
	void	SetTopView(int iTopView);
#endif
protected:  // control bar embedded members
	CStatusBar  m_wndStatusBar;
	CToolBar    m_wndToolBar;
	CArray	<CView*,CView*>m_arViewPointer;
	int m_iTopView;

// Generated message map functions
protected:
	//{{AFX_MSG(CMainFrame)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnEditUndo();
	afx_msg void OnEditCut();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};




BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs,CCreateContext* pContext )
{
	int f_iFirstView;
	int f_iSecondView;
	f_iFirstView = AddView(pContext);
	if(f_iFirstView < 0)
		return FALSE;
	//*/
	//在此处添加地图显示视图
	pContext->m_pNewViewClass = RUNTIME_CLASS(CSetViews);
	f_iSecondView = AddView(pContext);
	
	//SetTopView函数显示视图的切换功能,设置当前显示视类
	SetTopView(f_iSecondView);
	// m_iTopView=0;
	return TRUE;
	
}

int CMainFrame::AddView(CCreateContext *pContext)
{
	CView* f_pView = NULL;
	
	//最多支持255个视类对象,m_arViewPointer是数组,保存添加的视类个数
	if(m_arViewPointer.GetSize() >= 255)
		return -1;
	
	//检查入口参数有效性
	if (pContext != NULL && pContext->m_pNewViewClass != NULL)
	{
		//创建默认视
		f_pView = (CView*)CreateView(pContext, 
			AFX_IDW_PANE_LAST - m_arViewPointer.GetSize());
		if (f_pView == NULL)
			return FALSE;
		
		//隐藏新创建视
		f_pView->ShowWindow(SW_HIDE);
		//将视类指针加入队列
		return m_arViewPointer.Add(f_pView);
	}
	else
	{
		return -1;
	}
}

void CMainFrame::SetTopView(int iTopView)
{
	if((iTopView < 0)||(iTopView >= m_arViewPointer.GetSize()))
		return;
	
	CView* f_pOldTop = (CView*)m_arViewPointer[m_iTopView];
	CView* f_pNewTop = (CView*)m_arViewPointer[iTopView];
	
	//隐藏旧视图
	::SetWindowLong(f_pOldTop->m_hWnd, GWL_ID, (AFX_IDW_PANE_LAST-m_iTopView));
	f_pOldTop->ShowWindow(SW_HIDE);
	
	//显示新视图
	m_iTopView = iTopView;
	::SetWindowLong(f_pNewTop->GetSafeHwnd(), GWL_ID, (AFX_IDW_PANE_FIRST));
	f_pNewTop->ShowWindow(SW_SHOW);
	
	//刷新
	RecalcLayout();
}

#endif //_DEBUG

/
// CMainFrame message handlers


void CMainFrame::OnEditUndo() 
{
	// TODO: Add your command handler code here
	SetTopView(0);
}

void CMainFrame::OnEditCut() 
{
	// TODO: Add your command handler code here
	SetTopView(1);
}