📄 sample7view.cpp
字号:
// sample7View.cpp : implementation of the CSample7View class
//
#include "stdafx.h"
#include "sample7.h"
#include "sample7Doc.h"
#include "sample7View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static const CLSID CLSID_ApplicationGE = {0x8097D7E9,0xDB9E,0x4AEF, {0x9B,0x28,0x61,0xD8,0x2A,0x1D,0xF7,0x84}};
/////////////////////////////////////////////////////////////////////////////
// CSample7View
IMPLEMENT_DYNCREATE(CSample7View, CView)
BEGIN_MESSAGE_MAP(CSample7View, CView)
//{{AFX_MSG_MAP(CSample7View)
ON_COMMAND(IDC_START, OnStart)
ON_COMMAND(IDC_OPEN, OnOpen)
ON_COMMAND(IDC_SAVE, OnSave)
ON_COMMAND(IDC_CHANGE, OnChange)
ON_COMMAND(IDC_EXIT, OnExit)
ON_WM_TIMER()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CSample7View construction/destruction
CSample7View::CSample7View()
{
// TODO: add construction code here
::CoInitialize(NULL);
}
CSample7View::~CSample7View()
{
}
BOOL CSample7View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CSample7View drawing
void CSample7View::OnDraw(CDC* pDC)
{
CSample7Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CSample7View printing
BOOL CSample7View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSample7View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSample7View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CSample7View diagnostics
#ifdef _DEBUG
void CSample7View::AssertValid() const
{
CView::AssertValid();
}
void CSample7View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CSample7Doc* CSample7View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSample7Doc)));
return (CSample7Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSample7View message handlers
void CSample7View::OnStart()
{
// TODO: Add your command handler code here
if(TRUE==m_active)
{
AfxMessageBox("客户端已经启动!");
return;
}
m_active=TRUE;
if(m_geApplication.IsInitialized())
{
m_geApplication.CreateDispatch(CLSID_ApplicationGE,NULL);
if(!m_geApplication.IsOnline())
{
AfxMessageBox("已经连接上服务器!");
}
}
}
void CSample7View::OnOpen()
{
// TODO: Add your command handler code here
if(FALSE==m_active)
{
AfxMessageBox("客户端未启动!");
return;
}
CFileDialog geOpenDlg(TRUE); //初始化一个打开对话框的对象
geOpenDlg.m_ofn.lpstrTitle="Goolge Earth文件打开对话框";
geOpenDlg.m_ofn.lpstrFilter="KML Files(*.kml)\0*.kml\0All Files(*.*)\0*.*\0\0";
//完成KML文件的打开操作
if(IDOK==geOpenDlg.DoModal())
{
m_geApplication.OpenKmlFile(geOpenDlg.GetPathName(),TRUE);
}
}
void CSample7View::OnSave()
{
// TODO: Add your command handler code here
if(FALSE==m_active)
{
AfxMessageBox("客户端未启动!");
return;
}
CFileDialog geSaveDlg(FALSE); //初始化一个保存对话框的对象
geSaveDlg.m_ofn.lpstrTitle="Goolge Earth图象保存对话框";
geSaveDlg.m_ofn.lpstrFilter="JPG Files(*.jpg)\0*.jpg\0All Files(*.*)\0*.*\0\0";
geSaveDlg.m_ofn.lpstrDefExt="jpg";
//将当前视图保存为JPEG格式的黑白图象
if(IDOK==geSaveDlg.DoModal())
{
m_geApplication.SaveScreenShot(geSaveDlg.GetPathName(),100);
}
}
void CSample7View::OnChange()
{
// TODO: Add your command handler code here
int i(0),j(0),k(0);
//创建非模态对话框
pChangeDlg=new CCHANGEDLG();
pChangeDlg->Create(IDD_CHANGEDLG,this);
pChangeDlg->ShowWindow(SW_SHOW);
//获取名为hubei的kml文件
m_geFeature.AttachDispatch(m_geApplication.GetFeatureByName("hubei"),TRUE);
//获取hubei文件要素
m_geCollection.AttachDispatch(m_geFeature.GetChildren(),TRUE);
int countUp;
countUp=m_geCollection.GetCount(); //获取hubei文件夹中的文件数目
int* fileCount;
fileCount=new int[countUp];
IFeatureGE* feature;
feature=new IFeatureGE[countUp];
IFeatureCollectionGE* collection;
collection=new IFeatureCollectionGE[countUp];
for(i=0;i<countUp;i++)
{
//获取hubei文件中的子文件要素
feature[i].AttachDispatch(m_geCollection.GetItem(i+1),TRUE);
collection[i].AttachDispatch(feature[i].GetChildren(),TRUE);
//获取各子文件中的地标要素数目
fileCount[i]=collection[i].GetCount();
}
//获取地标要素总数
fileSum=0;
for(i=0;i<countUp;i++)
{
fileSum+=fileCount[i];
}
//重新定义地标要素数组
bFeature=new IFeatureGE[fileSum];
for(i=0;i<countUp;i++)
{
for(j=0;j<fileCount[i];j++)
{
bFeature[k].AttachDispatch(collection[i].GetItem(j+1),TRUE);
k++;
}
}
SetTimer(1,1500,NULL);
}
void CSample7View::OnExit()
{
// TODO: Add your command handler code here
HWND hwnd;
hwnd=(HWND)m_geApplication.GetMainHwnd();
//采用Windows消息函数关闭Google Earth客户端
::SendMessage(hwnd,WM_CLOSE,NULL,NULL);
m_geApplication.ReleaseDispatch();
}
void CSample7View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//获取在对话框单击【视图切换】按钮的次数
m_viewCount=pChangeDlg->m_viewCount;
//过滤m_viewCount值
int viewItem;
viewItem=m_viewCount%fileSum;
if(TRUE==bFeature[viewItem].GetHasView()) //判断该要素是否可视
{
//将视图中心移动到该要素所在位置
m_geApplication.SetFeatureView(bFeature[viewItem],3);
}
else
{
AfxMessageBox("KML文件不是二级目录!");
return; //如果该要素不可视,则拒绝显示
}
//m_geTimer用来控制Timer()函数
BOOL m_geTimer;
//判断是否停止调整操作
m_geTimer=pChangeDlg->IsTimer;
if(m_geTimer==FALSE)
{
KillTimer(1); //关闭Timer()函数
}
CView::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -