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

📄 geotestview.cpp

📁 一个简单的MapX+VC程序
💻 CPP
字号:
// GeoTestView.cpp : implementation of the CGeoTestView class
//

#include "stdafx.h"
#include "GeoTest.h"

#include "GeoTestDoc.h"
#include "GeoTestView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CGeoTestView

IMPLEMENT_DYNCREATE(CGeoTestView, CView)

BEGIN_MESSAGE_MAP(CGeoTestView, CView)
	//{{AFX_MSG_MAP(CGeoTestView)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_SETFOCUS()
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_VIEW_ARROW, OnViewArrow)
	ON_UPDATE_COMMAND_UI(ID_VIEW_ARROW, OnUpdateViewArrow)
	ON_COMMAND(ID_VIEW_ZOOMIN, OnViewZoomin)
	ON_UPDATE_COMMAND_UI(ID_VIEW_ZOOMIN, OnUpdateViewZoomin)
	ON_COMMAND(ID_VIEW_ZOOMOUT, OnViewZoomout)
	ON_UPDATE_COMMAND_UI(ID_VIEW_ZOOMOUT, OnUpdateViewZoomout)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGeoTestView construction/destruction

CGeoTestView::CGeoTestView()
{
	// TODO: add construction code here

}

CGeoTestView::~CGeoTestView()
{
}

BOOL CGeoTestView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CGeoTestView drawing

void CGeoTestView::OnDraw(CDC* pDC)
{
	CGeoTestDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CGeoTestView printing

BOOL CGeoTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CGeoTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CGeoTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CGeoTestView diagnostics

#ifdef _DEBUG
void CGeoTestView::AssertValid() const
{
	CView::AssertValid();
}

void CGeoTestView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CGeoTestDoc* CGeoTestView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGeoTestDoc)));
	return (CGeoTestDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CGeoTestView message handlers


int CGeoTestView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	m_ctrlMapX.Create(NULL,WS_VISIBLE,CRect(0,0,100,100),this,IDC_MAP);
	return 0;
}

void CGeoTestView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	if(m_ctrlMapX.m_hWnd!=NULL)
		m_ctrlMapX.MoveWindow(0,0,cx,cy,TRUE);
}

void CGeoTestView::OnSetFocus(CWnd* pOldWnd) 
{
	CView::OnSetFocus(pOldWnd);
	
	// TODO: Add your message handler code here
	m_ctrlMapX.SetFocus();
}

void CGeoTestView::OnFileOpen() 
{
	// TODO: Add your command handler code here
	CFileDialog dlgFile(TRUE);

	dlgFile.m_ofn.lpstrTitle = "地图查找";
	dlgFile.m_ofn.lpstrFilter = "MapInfo File (*.gst)\0*.gst\0All Files (*.*)\0*.*\0";

	if(IDOK != dlgFile.DoModal())
		return;
	m_ctrlMapX.SetGeoSet(dlgFile.GetFileName());

	CMapXStyle mxStyle;
	HDC hdc;
//	mxStyle.Create(mxStyle.GetClsid());
	mxStyle.CreateDispatch(mxStyle.GetClsid());
	mxStyle.DrawSymbolSample(hdc,CRect(0,0,20,20));

	CMapXFeature newobj;
	CMapXFeature obj;
	
	if(!newobj.CreateDispatch(newobj.GetClsid()))
	{
		TRACE0("Failed create feature object\n");
		return;
	}

	try
	{
		newobj.Attach(m_ctrlMapX.GetDispatch());
		newobj.SetType(miFeatureTypeSymbol);

		newobj.SetStyle(m_ctrlMapX.GetDefaultStyle());
		newobj.GetPoint().Set(-0.1231,0.0000);

		obj = m_ctrlMapX.GetLayers().Item(1).AddFeature(newobj);
	}
	catch(COleDispatchException *e)
	{
		e->ReportError();
		e->Delete();
	}
	catch(COleException *e)
	{
		e->ReportError();
		e->Delete();
	}
}

void CGeoTestView::OnViewArrow() 
{
	// TODO: Add your command handler code here
	m_ctrlMapX.SetCurrentTool(miArrowTool);
}

void CGeoTestView::OnUpdateViewArrow(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(m_ctrlMapX.m_hWnd != NULL)
	{
		pCmdUI->Enable(TRUE);
	}
	else
	{
		pCmdUI->Enable(FALSE);
	}
	pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool() == miArrowTool);
}

void CGeoTestView::OnViewZoomin() 
{
	// TODO: Add your command handler code here
	m_ctrlMapX.SetCurrentTool(miZoomInTool);
}

void CGeoTestView::OnUpdateViewZoomin(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(m_ctrlMapX.m_hWnd != NULL)
	{
		pCmdUI->Enable(TRUE);
	}
	else
	{
		pCmdUI->Enable(FALSE);
	}
	pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()== miZoomInTool);
}

void CGeoTestView::OnViewZoomout() 
{
	// TODO: Add your command handler code here
	m_ctrlMapX.SetCurrentTool(miZoomOutTool);
	//m_ctrlMapX.GetDefaultStyle();
}

void CGeoTestView::OnUpdateViewZoomout(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(m_ctrlMapX.m_hWnd != NULL)
	{
		pCmdUI->Enable(TRUE);
	}
	else
	{
		pCmdUI->Enable(FALSE);
	}
	pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool() == miZoomOutTool);
}

⌨️ 快捷键说明

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