Google Earth VS2008開發

1.安裝Google Earth。

2.在解決方案中添加對EARTHLib COM組件的引用。

 

 

3.引用EARTHLib 和 System.Runtime.InteropServices。

  1. using EARTHLib;
  2. using System.Runtime.InteropServices;

4.添加函數聲明

  1.         public delegate int EnumWindowsProc(IntPtr hwnd, int lParam);
  2.         [DllImport("user32", CharSet = CharSet.Auto)]
  3.         public extern static IntPtr GetParent(IntPtr hWnd);
  4.         [DllImport("user32", CharSet = CharSet.Auto)]
  5.         public extern static bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
  6.         [DllImport("user32", CharSet = CharSet.Auto)]
  7.         public extern static IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

5.在一個C# 中WINFORM中顯示Google Earth

  1. ApplicationGEClass application
  2. private IntPtr GEHrender = (IntPtr)0;//Google Earth的句柄 
  3. private IntPtr GEParentHrender = (IntPtr)0;//Google Earth容器的句柄 
  4. application = new ApplicationGEClass();//實例化一個Google Earth 
  5. GEHrender = (IntPtr)application.GetRenderHwnd();
  6. GEParentHrender = GetParent(GEHrender);

6.調用Win32的api調整窗口的位置和大小

  1. MoveWindow(GEHrender,0,0, 800, 600, true);//窗口句柄,窗口的位置,窗口的大小,是否重繪

7.設定Google Earth的容器

  1. SetParent(GEHrender, this.Handle);//GE的句柄,容器的句柄

8.運行結果

 

9.也可以綁定到Panel等佈局容器的句柄

  1.  SetParent(GEHrender, this.splitContainer1.Panel2.Handle);

10.運行結果

 

 

 

如果想在WPF中加入Google Earth的話 方式有點不同但是原理都是一樣的,有時間的話我會寫出來和大家分享:)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章