WEB开发网
开发学院软件开发C语言 C# 调用 Google Earth Com API开发(二) 阅读

C# 调用 Google Earth Com API开发(二)

 2009-05-22 08:29:53 来源:WEB开发网   
核心提示:继《C#调用GoogleEarth Com API开发(一)》,我Neil又带给大家第二篇文章,C# 调用 Google Earth Com API开发(二),这一篇文章在第一篇的基础上,展示如何调用Windows API将GoogleEarth的界面隐藏掉,并将GoogleEarth的地图显示在自定义的窗体上,废话少

继《C#调用GoogleEarth Com API开发(一)》,我Neil又带给大家第二篇文章。这一篇文章在第一篇的基础上,展示如何调用Windows API将GoogleEarth的界面隐藏掉,并将GoogleEarth的地图显示在自定义的窗体上。废话少说,直接上代码。

1、主窗口代码:

  1: // 功能:GE实例(二)
  2: // 描述:GE COM API 网址:http://earth.google.com/comapi/index.html
  3: // 作者:温伟鹏
  4: // 日期:2009-02-08
  5:  
  6: using System;
  7: using System.Collections.Generic;
  8: using System.ComponentModel;
  9: using System.Data;
 10: using System.Drawing;
 11: using System.Text;
 12: using System.Windows.Forms;
 13: using EARTHLib;
 14:  
 15: namespace GEDemo
 16: {
 17:   public partial class Form2 : Form
 18:   {
 19:     /// <summary>
 20:     /// 用来关闭GoogleEarth的消息定义
 21:     /// </summary>
 22:     static readonly Int32 WM_QUIT = 0x0012; 
 23:  
 24:     private IntPtr GEHWnd = (IntPtr)5;
 25:     private IntPtr GEHrender = (IntPtr)5;
 26:     private IntPtr GEParentHrender = (IntPtr)5;
 27:     /// <summary>
 28:     /// 定义GE应用程序类
 29:     /// </summary>
 30:     private ApplicationGEClass GeApp;
 31:  
 32:     public Form2()
 33:     {
 34:       InitializeComponent();
 35:     }
 36:  
 37:     protected override void OnLoad(EventArgs e)
 38:     {
 39:       base.OnLoad(e);
 40:  
 41:       if (!this.DesignMode)
 42:       {
 43:         GeApp = new ApplicationGEClass();
 44:  
 45:         GEHWnd = (IntPtr)GeApp.GetMainHwnd();
 46:  
 47:         NativeMethods.SetWindowPos(GEHWnd, NativeMethods.HWND_BOTTOM, 0, 0, 0, 0,
 48:           NativeMethods.SWP_NOSIZE + NativeMethods.SWP_HIDEWINDOW);
 49:  
 50:         GEHrender = (IntPtr)GeApp.GetRenderHwnd();
 51:         GEParentHrender = (IntPtr)NativeMethods.GetParent(GEHrender);
 52:  
 53:         NativeMethods.MoveWindow(GEHrender, 0, 0, this.Width, this.Height, true);
 54:  
 55:         NativeMethods.SetParent(GEHrender, this.Handle);
 56:       }
 57:     }
 58:  
 59:     protected override void OnClosing(CancelEventArgs e)
 60:     {
 61:       base.OnClosing(e);
 62:  
 63:       NativeMethods.PostMessage(GeApp.GetMainHwnd(), WM_QUIT, 0, 0);
 64:     }
 65:   }
 66: }

1 2  下一页

Tags:调用 Google Earth

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接