📄 testview.cpp
字号:
// TestView.cpp : implementation of the CTestView class
//
#include "stdafx.h"
#include "Test.h"
#include "Mainfrm.h"
#include "TestDoc.h"
#include "TestView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestView
IMPLEMENT_DYNCREATE(CTestView, CFormView)
BEGIN_MESSAGE_MAP(CTestView, CFormView)
//{{AFX_MSG_MAP(CTestView)
ON_COMMAND(ID_ZOOMIN, OnZoomin)
ON_COMMAND(ID_ZOOMOUT, OnZoomout)
ON_COMMAND(ID_BROWSE, OnBrowse)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
ON_WM_SIZE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestView construction/destruction
CTestView::CTestView()
: CFormView(CTestView::IDD)
{
//{{AFX_DATA_INIT(CTestView)
m_StrXY = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CTestView::~CTestView()
{
}
void CTestView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestView)
DDX_Control(pDX, IDC_COMBO1, m_State);
DDX_Control(pDX, IDC_MAP1, m_Map);
DDX_Text(pDX, IDC_EDIT1, m_StrXY);
//}}AFX_DATA_MAP
}
BOOL CTestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CTestView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CTestView printing
BOOL CTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CTestView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CTestView diagnostics
#ifdef _DEBUG
void CTestView::AssertValid() const
{
CFormView::AssertValid();
}
void CTestView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CTestDoc* CTestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestDoc)));
return (CTestDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTestView message handlers
void CTestView::OnZoomin()
{
// TODO: Add your command handler code here
m_Map.SetCurrentTool(1003);
}
void CTestView::OnZoomout()
{
// TODO: Add your command handler code here
m_Map.SetCurrentTool(1004);
}
void CTestView::OnBrowse()
{
// TODO: Add your command handler code here
m_Map.SetCurrentTool(1001);
}
void CTestView::OnButton1()
{
// TODO: Add your control notification handler code here
CMapXLayers layers;
CMapXLayer layer;
layers=m_Map.GetLayers();
long layercount=layers.GetCount();
CString str;
str.Format("layer count=%d",layercount);
AfxMessageBox(str);
for(int i=0;i<layercount;i++)
{
layer=layers.Item(i+1);
AfxMessageBox(layer.GetName());
}
}
void CTestView::OnButton2()
{
// TODO: Add your control notification handler code here
CMapXLayers layers;
char FileFilter[] = "Gst File(*.gst)|*.gst|";
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,FileFilter);
//CFileDialog dlg(TRUE,NULL);
if(dlg.DoModal()==IDOK)
{
CString str=dlg.GetPathName();
layers.AddGeoSetLayers(str);
}
}
void CTestView::OnButton3()
{
// TODO: Add your control notification handler code here
CMapXLayers layers;
layers=m_Map.GetLayers();
layers.LayersDlg();
}
void CTestView::OnButton4()
{
// TODO: Add your control notification handler code here
m_Map.CreateCustomTool(99,miToolTypeLine,miCrossCursor);
m_Map.SetCurrentTool(99);
}
BEGIN_EVENTSINK_MAP(CTestView, CFormView)
//{{AFX_EVENTSINK_MAP(CTestView)
ON_EVENT(CTestView, IDC_MAP1, -606 /* MouseMove */, OnMouseMoveMap1, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
ON_EVENT(CTestView, IDC_MAP1, 3 /* ToolUsed */, OnToolUsedMap1, VTS_I2 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_BOOL VTS_BOOL VTS_PBOOL)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CTestView::OnMouseMoveMap1(short Button, short Shift, float X, float Y)
{
// TODO: Add your control notification handler code here
double xcoord,ycoord;
CString m_MapXY;
SYSTEMTIME st;
CString strDate,strTime;
GetLocalTime(&st);
strDate.Format("%4d-%2d-%2d",st.wYear,st.wMonth,st.wDay);
strTime.Format("%2d:%2d:%2d",st.wHour,st.wMinute,st.wSecond);
m_Map.ConvertCoord(&X,&Y,&xcoord,&ycoord,1);
m_StrXY.Format("ScremX=%.2f,ScremY=%.2f",X,Y);
m_MapXY.Format("MapX=%.2f,MapY=%.2f",xcoord,ycoord);
CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
CStatusBar* pStatus=&pFrame->m_wndStatusBar;
if(pStatus)
{
pStatus->SetPaneText(0,m_MapXY);
pStatus->SetPaneText(2,strTime);
}
UpdateData(FALSE);
}
void CTestView::OnToolUsedMap1(short ToolNum, double X1, double Y1, double X2, double Y2, double Distance, BOOL Shift, BOOL Ctrl, BOOL FAR* EnableDefault)
{
// TODO: Add your control notification handler code here
if(ToolNum==99)
{
CString str;
str.Format("Distance = %.2f",Distance);
AfxMessageBox(str);
}
}
void CTestView::OnButton5()
{
// TODO: Add your control notification handler code here
CMapXLayerFind find = layer.GetFind();
CMapXFindFeature FoundObject =
find.Search(m_strFindState);
AfxMessageBox(FoundObject.GetName());
CString str;
str.Format("Area = %.2f",FoundObject.GetArea());
AfxMessageBox(str);
double dX,dY;
dX = FoundObject.GetCenterX();
dY = FoundObject.GetCenterY();
m_Map.SetCenterX(dX);
m_Map.SetCenterY(dY);
CMapXSelection Selection = layer.GetSelection();
Selection.SelectByPoint(dX,dY, miSelectionNew);
}
void CTestView::OnSelchangeCombo1()
{
// TODO: Add your control notification handler code here
m_State.GetLBText(m_State.GetCurSel(),m_strFindState);
}
void CTestView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
if(m_Map.m_hWnd != NULL)
{
// TODO: Add your message handler code here
layers = m_Map.GetLayers();
layer = layers.Item("WORLD");
CMapXFeatures fs = layer.AllFeatures();
for(int i=0;i<2;i++)
{
m_State.AddString(fs.Item(i+1).GetName());
}
m_State.SetCurSel(0);
}
}
void CTestView::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
CFormView::PostNcDestroy();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -