當前位置:編程學習大全網 - 編程語言 - 在VC++6.0中如何用Mapx進行GIS系統的開發,或者給壹個小的項目源代碼也行呀?!

在VC++6.0中如何用Mapx進行GIS系統的開發,或者給壹個小的項目源代碼也行呀?!

利用GIS 工具軟件生產廠家提供的建立在OCX 技術基礎上的GIS 功能控件,如ESRI

的MapObjects、MapInfo 公司的MapX 等,在Delphi 等編程工具編制的應用程序中,直

接將GIS 功能嵌入其中,實現地理信息系統的各種功能。

需要先下載mapx控件,然後就可以在VC環境中,加入該控件,妳當然可以選擇在對話框上直接插入控件mapx,當做壹個控件使用,也可以在文檔視圖中插入控件,將相應類文件加入其中,包含了mapx.h 文件後,可以定義相應變量,在OnCreate中創建,還可以做其他事情,下面是壹個代碼,僅供參考。

// GeoExpertView.h : interface of the CGeoExpertView class

//

/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_GEOEXPERTVIEW_H__3456F63F_3DC9_493F_8817_DAA44E0779AE__INCLUDED_)

#define AFX_GEOEXPERTVIEW_H__3456F63F_3DC9_493F_8817_DAA44E0779AE__INCLUDED_

#if _MSC_VER > 1000

#pragma once

#endif // _MSC_VER > 1000

#include "MapX.h"

class CGeoExpertView : public CView

{

protected: // create from serialization only

CGeoExpertView();

DECLARE_DYNCREATE(CGeoExpertView)

// Attributes

public:

CGeoExpertDoc* GetDocument();

// Operations

public:

// Overrides

// ClassWizard generated virtual function overrides

//{{AFX_VIRTUAL(CGeoExpertView)

public:

virtual void OnDraw(CDC* pDC); // overridden to draw this view

virtual BOOL PreCreateWindow(CREATESTRUCT& cs);

protected:

virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);

virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);

virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);

//}}AFX_VIRTUAL

// Implementation

public:

CString m_strFilePath;

CMapX m_ctrlMapX;

virtual ~CGeoExpertView();

#ifdef _DEBUG

virtual void AssertValid() const;

virtual void Dump(CDumpContext& dc) const;

#endif

protected:

// Generated message map functions

protected:

//{{AFX_MSG(CGeoExpertView)

afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);

afx_msg void OnSize(UINT nType, int cx, int cy);

afx_msg void OnSetFocus(CWnd* pOldWnd);

afx_msg void OnFileOpen();

afx_msg void OnMapToolArrow();

afx_msg void OnMapToolZoomin();

afx_msg void OnMapToolZoomout();

afx_msg void OnMapToolPan();

afx_msg void OnMapToolSelect();

afx_msg void OnMapToolRectangleselect();

afx_msg void OnMapToolRadiusselect();

afx_msg void OnViewLayercontrol();

afx_msg void OnMapToolEntire();

afx_msg void OnUpdateMapToolZoomin(CCmdUI* pCmdUI);

afx_msg void OnUpdateMapToolZoomout(CCmdUI* pCmdUI);

afx_msg void OnUpdateMapToolPan(CCmdUI* pCmdUI);

afx_msg void OnUpdateMapToolArrow(CCmdUI* pCmdUI);

afx_msg void OnUpdateMapToolSelect(CCmdUI* pCmdUI);

afx_msg void OnUpdateMapToolRectangleselect(CCmdUI* pCmdUI);

afx_msg void OnUpdateMapToolRadiusselect(CCmdUI* pCmdUI);

afx_msg void OnMapToolCenter();

afx_msg void OnUpdateMapToolCenter(CCmdUI* pCmdUI);

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

#ifndef _DEBUG // debug version in GeoExpertView.cpp

inline CGeoExpertDoc* CGeoExpertView::GetDocument()

{ return (CGeoExpertDoc*)m_pDocument; }

#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}

// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_GEOEXPERTVIEW_H__3456F63F_3DC9_493F_8817_DAA44E0779AE__INCLUDED_)

// GeoExpertView.cpp : implementation of the CGeoExpertView class

//

#include "stdafx.h"

#include "GeoExpert.h"

#include "GeoExpertDoc.h"

#include "GeoExpertView.h"

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif

/////////////////////////////////////////////////////////////////////////////

// CGeoExpertView

IMPLEMENT_DYNCREATE(CGeoExpertView, CView)

BEGIN_MESSAGE_MAP(CGeoExpertView, CView)

//{{AFX_MSG_MAP(CGeoExpertView)

ON_WM_CREATE()

ON_WM_SIZE()

ON_WM_SETFOCUS()

ON_COMMAND(ID_FILE_OPEN, OnFileOpen)

ON_COMMAND(ID_MAP_TOOL_ARROW, OnMapToolArrow)

ON_COMMAND(ID_MAP_TOOL_ZOOMIN, OnMapToolZoomin)

ON_COMMAND(ID_MAP_TOOL_ZOOMOUT, OnMapToolZoomout)

ON_COMMAND(ID_MAP_TOOL_PAN, OnMapToolPan)

ON_COMMAND(ID_MAP_TOOL_SELECT, OnMapToolSelect)

ON_COMMAND(ID_MAP_TOOL_RECTANGLESELECT, OnMapToolRectangleselect)

ON_COMMAND(ID_MAP_TOOL_RADIUSSELECT, OnMapToolRadiusselect)

ON_COMMAND(ID_VIEW_LAYERCONTROL, OnViewLayercontrol)

ON_COMMAND(ID_MAP_TOOL_ENTIRE, OnMapToolEntire)

ON_UPDATE_COMMAND_UI(ID_MAP_TOOL_ZOOMIN, OnUpdateMapToolZoomin)

ON_UPDATE_COMMAND_UI(ID_MAP_TOOL_ZOOMOUT, OnUpdateMapToolZoomout)

ON_UPDATE_COMMAND_UI(ID_MAP_TOOL_PAN, OnUpdateMapToolPan)

ON_UPDATE_COMMAND_UI(ID_MAP_TOOL_ARROW, OnUpdateMapToolArrow)

ON_UPDATE_COMMAND_UI(ID_MAP_TOOL_SELECT, OnUpdateMapToolSelect)

ON_UPDATE_COMMAND_UI(ID_MAP_TOOL_RECTANGLESELECT, OnUpdateMapToolRectangleselect)

ON_UPDATE_COMMAND_UI(ID_MAP_TOOL_RADIUSSELECT, OnUpdateMapToolRadiusselect)

ON_COMMAND(ID_MAP_TOOL_CENTER, OnMapToolCenter)

ON_UPDATE_COMMAND_UI(ID_MAP_TOOL_CENTER, OnUpdateMapToolCenter)

//}}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()

/////////////////////////////////////////////////////////////////////////////

// CGeoExpertView construction/destruction

CGeoExpertView::CGeoExpertView()

{

// TODO: add construction code here

}

CGeoExpertView::~CGeoExpertView()

{

}

BOOL CGeoExpertView::PreCreateWindow(CREATESTRUCT& cs)

{

// TODO: Modify the Window class or styles here by modifying

// the CREATESTRUCT cs

return CView::PreCreateWindow(cs);

}

/////////////////////////////////////////////////////////////////////////////

// CGeoExpertView drawing

void CGeoExpertView::OnDraw(CDC* pDC)

{

CGeoExpertDoc* pDoc = GetDocument();

ASSERT_VALID(pDoc);

// TODO: add draw code for native data here

}

/////////////////////////////////////////////////////////////////////////////

// CGeoExpertView printing

BOOL CGeoExpertView::OnPreparePrinting(CPrintInfo* pInfo)

{

// default preparation

return DoPreparePrinting(pInfo);

}

void CGeoExpertView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)

{

// TODO: add extra initialization before printing

}

void CGeoExpertView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)

{

// TODO: add cleanup after printing

}

/////////////////////////////////////////////////////////////////////////////

// CGeoExpertView diagnostics

#ifdef _DEBUG

void CGeoExpertView::AssertValid() const

{

CView::AssertValid();

}

void CGeoExpertView::Dump(CDumpContext& dc) const

{

CView::Dump(dc);

}

CGeoExpertDoc* CGeoExpertView::GetDocument() // non-debug version is inline

{

ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGeoExpertDoc)));

return (CGeoExpertDoc*)m_pDocument;

}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////

// CGeoExpertView message handlers

int CGeoExpertView::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

if (CView::OnCreate(lpCreateStruct) == -1)

return -1;

// TODO: Add your specialized creation code here

RECT windRect;

GetClientRect(&windRect);

if (!m_ctrlMapX.Create(NULL, WS_VISIBLE, windRect, this,IDC_MAP))

return -1;

return 0;

}

void CGeoExpertView::OnSize(UINT nType, int cx, int cy)

{

CView::OnSize(nType, cx, cy);

// TODO: Add your message handler code here

//if (cx != 0 && cy != 0)

if (m_ctrlMapX.m_hWnd != NULL)

m_ctrlMapX.MoveWindow(0,0,cx,cy,TRUE);

}

void CGeoExpertView::OnSetFocus(CWnd* pOldWnd)

{

CView::OnSetFocus(pOldWnd);

// TODO: Add your message handler code here

m_ctrlMapX.SetFocus();

}

static char BASED_CODE szTabFilter[] = "MapInfo Map Files (*.gst)|*.gst|All Files (*.*)|*.*||";

void CGeoExpertView::OnFileOpen()

{

// TODO: Add your command handler code here

CFileDialog dlgFile(TRUE, "*.gst", NULL, OFN_HIDEREADONLY , szTabFilter, this);

dlgFile.m_ofn.lpstrTitle = "Open MapInfo Map";

if (dlgFile.DoModal() == IDCANCEL)

return;

m_strFilePath = dlgFile.GetPathName();

try {

// Close the existing set of map layers and load the Canada map

TRACE0("Old Geoset: " + m_ctrlMapX.GetGeoSet());

m_ctrlMapX.SetGeoSet(m_strFilePath);

//m_ctrlMapX.SetTitleText("");

TRACE0("New Geoset: " + m_ctrlMapX.GetGeoSet());

}

catch (COleDispatchException *e) {

e->ReportError();

e->Delete();

}

catch (COleException *e) {

e->ReportError();

e->Delete();

}

}

void CGeoExpertView::OnMapToolArrow()

{

// TODO: Add your command handler code here

m_ctrlMapX.SetCurrentTool(miArrowTool);

}

void CGeoExpertView::OnMapToolZoomin()

{

// TODO: Add your command handler code here

m_ctrlMapX.SetCurrentTool(miZoomInTool);

}

void CGeoExpertView::OnMapToolZoomout()

{

// TODO: Add your command handler code here

m_ctrlMapX.SetCurrentTool(miZoomOutTool);

}

void CGeoExpertView::OnMapToolPan()

{

// TODO: Add your command handler code here

m_ctrlMapX.SetCurrentTool(miPanTool);

}

void CGeoExpertView::OnMapToolSelect()

{

// TODO: Add your command handler code here

m_ctrlMapX.SetCurrentTool(miSelectTool);

}

void CGeoExpertView::OnMapToolRectangleselect()

{

// TODO: Add your command handler code here

m_ctrlMapX.SetCurrentTool(miRectSelectTool);

}

void CGeoExpertView::OnMapToolRadiusselect()

{

// TODO: Add your command handler code here

m_ctrlMapX.SetCurrentTool(miRadiusSelectTool);

}

void CGeoExpertView::OnMapToolCenter()

{

// TODO: Add your command handler code here

m_ctrlMapX.SetCurrentTool(miCenterTool);

}

void CGeoExpertView::OnMapToolEntire()

{

// TODO: Add your command handler code here

/*

try {

m_ctrlMapX.SetZoom(m_ctrlMapX.GetGeoSetWidth());

}

catch (COleDispatchException *e) {

e->ReportError();

e->Delete();

}

catch (COleException *e) {

e->ReportError();

e->Delete();

}

*/

m_ctrlMapX.SetGeoSet(m_strFilePath);

}

void CGeoExpertView::OnViewLayercontrol()

{

// TODO: Add your command handler code here

try {

VARIANT vHelpFile, vHelpID; // mark as optional since we don't have a helpfile

vHelpFile.vt = VT_ERROR;

vHelpFile.scode = DISP_E_PARAMNOTFOUND;

vHelpID.vt = VT_ERROR;

vHelpID.scode = DISP_E_PARAMNOTFOUND;

CMapXLayers layers = m_ctrlMapX.GetLayers();

layers.LayersDlg(vHelpFile, vHelpID);

}

catch (COleDispatchException *e) {

e->ReportError();

e->Delete();

}

catch (COleException *e) {

e->ReportError();

e->Delete();

}

}

void CGeoExpertView::OnUpdateMapToolArrow(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 CGeoExpertView::OnUpdateMapToolZoomin(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 CGeoExpertView::OnUpdateMapToolZoomout(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);

}

void CGeoExpertView::OnUpdateMapToolPan(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() == miPanTool);

}

void CGeoExpertView::OnUpdateMapToolSelect(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() == miSelectTool);

}

void CGeoExpertView::OnUpdateMapToolRectangleselect(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() == miRectSelectTool);

}

void CGeoExpertView::OnUpdateMapToolRadiusselect(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() == miRadiusSelectTool);

}

void CGeoExpertView::OnUpdateMapToolCenter(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() == miCenterTool);

}

  • 上一篇:進入IT企業必讀的200個 .NET面試題的目 錄
  • 下一篇:軟件工程師和軟件開發工程師壹樣嗎?
  • copyright 2024編程學習大全網