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

📄 mapxsampleview.cpp

📁 vc+mapx二次开发示例程序。包括地图读取
💻 CPP
字号:
// MapXSampleView.cpp : implementation of the CMapXSampleView class
//

#include "stdafx.h"
#include "MapXSample.h"

#include "MapXSampleDoc.h"
#include "MapXSampleView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView

IMPLEMENT_DYNCREATE(CMapXSampleView, CView)

BEGIN_MESSAGE_MAP(CMapXSampleView, CView)
	//{{AFX_MSG_MAP(CMapXSampleView)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_SETFOCUS()
	ON_COMMAND(ID_ZOOMIN, OnZoomin)
	ON_COMMAND(ID_ZOOMOUT, OnZoomout)
	ON_COMMAND(ID_MOVE, OnMove)
	ON_COMMAND(ID_INFO, OnInfo)
	ON_COMMAND(ID_SELECT_BY_PT, OnSelectByPt)
	ON_COMMAND(ID_SELECT_BY_CIRCLE, OnSelectByCircle)
	ON_COMMAND(ID_SELECT_BY_RECT, OnSelectByRect)
	ON_COMMAND(ID_SELECT_BY_POLY, OnSelectByPoly)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_LayersDialog, OnLayersDialog)
	ON_COMMAND(ID_DispFull, OnDispFull)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView construction/destruction

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

}

CMapXSampleView::~CMapXSampleView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView drawing

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

/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMapXSampleView message handlers

int CMapXSampleView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	// create map with default size
	// resize message will cause it to be
	// size to the client area of the view

//	if (!m_ctrlMapX.Create(NULL, WS_VISIBLE, CRect(0,0,100,100),this,IDC_MAP))
//		return -1;
	SetCapture();
	BeginWaitCursor();
	try 
	{
		//取当前路径
		char CurrentPath[ 80 ];
		GetCurrentDirectory(80,CurrentPath);
		char m_strPath[120];
		strcpy(m_strPath,CurrentPath);
		strcat(m_strPath,"\\Mapdata\\湖南图.gst");



		//创建MapX地图对象
		CRect ViewRect;
		GetClientRect( ViewRect);
		m_ctrlMapX.Create( NULL,WS_VISIBLE,ViewRect,this,IDC_MAP );

		//设置MapInfo数字地图
		m_ctrlMapX.SetGeoSet(m_strPath);
		m_ctrlMapX.SetMousePointer(miHourglassCursor);		//设置鼠标形状
		m_ctrlMapX.SetRedrawInterval(150);					//绘图延迟时间0.001秒
		CString str=m_ctrlMapX.GetTitleText();
		m_ctrlMapX.SetTitleText(str);
		m_ctrlMapX.SetMapUnit(1);
		m_bMapData=TRUE;
			
	}
	catch ( COleDispatchException *e)
	{
		e->ReportError();
		e->Delete();
	}
	catch ( COleException *e)
	{
		e->ReportError();
		e->Delete();
	}
	ReleaseCapture();
	EndWaitCursor();
	m_ctrlMapX.SetMousePointer(0);
	

//	if ( !m_ctrlMapX.Create( NULL ,WS_VISIBLE , CRect(0,0,100,100),this,IDC_MAP ))
//		return -1;
///	return 0;
	
	return 0;
}

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

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

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

void CMapXSampleView::OnZoomout() 
{
	// TODO: Add your command handler code here
	m_ctrlMapX.SetCurrentTool(miZoomOutTool);
	
}

void CMapXSampleView::OnMove() 
{
	// TODO: Add your command handler code here
	m_ctrlMapX.SetCurrentTool(miPanTool);
	
}

void CMapXSampleView::OnInfo() 
{
	// TODO: Add your command handler code here

	
}

void CMapXSampleView::OnSelectByPt() 
{
	// TODO: Add your command handler code here
	m_ctrlMapX.SetCurrentTool(miSelectTool);
	
}

void CMapXSampleView::OnSelectByCircle() 
{
	// TODO: Add your command handler code here
	m_ctrlMapX.SetCurrentTool(miRadiusSelectTool);
	
}

void CMapXSampleView::OnSelectByRect() 
{
	// TODO: Add your command handler code here
	m_ctrlMapX.SetCurrentTool(miRectSelectTool);
	
}

void CMapXSampleView::OnSelectByPoly() 
{
	// TODO: Add your command handler code here
	m_ctrlMapX.SetCurrentTool(miPolygonSelectTool);	
}

void CMapXSampleView::OnFileOpen() 
{
	// TODO: Add your command handler code here
CString OpenedFileName;
	CFileDialog fdlg(TRUE,"gst","*.gst",OFN_OVERWRITEPROMPT, "Mapinfo Geoset(*.gst)|*.gst| All files (*.*)|*.*||", NULL);
    if(fdlg.DoModal()==IDOK)
    {
		OpenedFileName=fdlg.GetFileName();
	}
	else
	{
		return;
	}

	char szFilename[120];//文件名变量

	GetCurrentDirectory(120, szFilename);

    strcpy(szFilename,OpenedFileName);  
	if (strcmp(OpenedFileName,"NULL")==0)//对搜索的结果进行处理
	{
		MessageBox("没有找到文件,文件不存在或已经损坏!","提醒",1);
		return;
	}
	////////////////////////////////////////
 
 
}

void CMapXSampleView::OnLayersDialog() 
{
	// TODO: Add your command handler code here
	m_ctrlMapX.GetLayers().LayersDlg();
	
}

void CMapXSampleView::OnDispFull() 
{
	// TODO: Add your command handler code here
//	m_ctrlMapX.SetBounds(m_ctrlMapX.GetLayers().GetBounds());
//	m_ctrlMapX.SetMousePointer(miArrowCursor);

	CString mapname=m_ctrlMapX.GetGeoSet();//取得当前地图的名字

	m_ctrlMapX.SetGeoSet(mapname);//设置该地图为主视区显示图

	
}

⌨️ 快捷键说明

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