⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 有用的参考文件
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "MapDemo.h"
#include "MapDemoDoc.h"
#include "MapView.h"
#include "MapFormView.h"
#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_WM_PALETTECHANGED()
	ON_WM_QUERYNEWPALETTE()
	ON_COMMAND(ID_WINDOW_FROMVIEW, OnWindowFromview)
	ON_COMMAND(ID_WINDOW_MAPVIEW, OnWindowMapview)
	//}}AFX_MSG_MAP
	// Global help commands
	ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
	ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
	ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
	ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
  m_pMapView=NULL;
  m_pFormView=NULL;
	
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndToolBarMap.Create(this) ||
		!m_wndToolBarMap.LoadToolBar(IDR_TOOLBARMAP))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}


	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	EnableDocking(CBRS_ALIGN_ANY);

    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	m_wndToolBarMap.EnableDocking(CBRS_ALIGN_ANY);

	DockControlBar(&m_wndToolBar);
	DockControlBar(&m_wndToolBarMap, AFX_IDW_DOCKBAR_LEFT);

	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CMDIFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
		| WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CMDIFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CMDIFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers


void CMainFrame::OnPaletteChanged(CWnd* pFocusWnd) 
{
	
	CMapDemoApp::GetApp()->NotifyPaletteChanged(pFocusWnd);
	CMDIFrameWnd::OnPaletteChanged(pFocusWnd);
	
	// TODO: Add your message handler code here
	
}

BOOL CMainFrame::OnQueryNewPalette() 
{
	CMDIChildWnd* pChildView = MDIGetActive();
	if( pChildView ) {
		CMapView* pView = (CMapView*) pChildView->GetActiveView();
		if( pView ) {
			pView->NotifyQueryNewPalette();
		}
	}
	return CMDIFrameWnd::OnQueryNewPalette();
}

void CMainFrame::OnWindowFromview() 
{ 
	if(m_pFormView==NULL) 
	{
		CMDIChildWnd* pActiveChild=MDIGetActive();
		CDocument* pDocument;
		if(pActiveChild!=NULL&&(pDocument=pActiveChild->GetActiveDocument())!=NULL)
		{
			CDocTemplate* pTemplate=((CMapDemoApp*)AfxGetApp())->pFormTemplate;
			CFrameWnd* pFrame=pTemplate->CreateNewFrame(pDocument,pActiveChild);
			pTemplate->InitialUpdateFrame(pFrame,pDocument);
			
        }
    }
	else{

	SetActiveView(m_pFormView);
	m_pFormView->ShowWindow(SW_SHOW);

	}
}

void CMainFrame::OnWindowMapview() 
{

	if(m_pMapView==NULL) 
	{
		CMDIChildWnd* pActiveChild=MDIGetActive();
		CDocument* pDocument;
		if(pActiveChild!=NULL&&(pDocument=pActiveChild->GetActiveDocument())!=NULL)
		{
			CDocTemplate* pTemplate=((CMapDemoApp*)AfxGetApp())->pDocTemplate;
			CFrameWnd* pFrame=pTemplate->CreateNewFrame(pDocument,pActiveChild);
			pTemplate->InitialUpdateFrame(pFrame,pDocument);
			
        }
    }
	else{

	SetActiveView(m_pMapView);
	m_pMapView->ShowWindow(SW_SHOW);

	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -