google earth参考代码

 


     
     
//---------------------------------   
  [DllImport("user32.dll", CharSet = CharSet.Auto)] 
 public extern static bool SetWindowPos(int hWnd, IntPtr hWndInsertAfter,
 int X, int Y, int cx, int cy, uint uFlags);  
   [DllImport("user32.dll", CharSet = CharSet.Auto)] 
 public static extern IntPtr PostMessage(int hWnd, int msg, int wParam, int lParam);  
   [DllImport("user32", CharSet = CharSet.Auto)]  public extern static IntPtr GetParent(IntPtr hWnd);  
   [DllImport("user32", CharSet = CharSet.Auto)]  public extern static bool MoveWindow(IntPtr hWnd, int X, 
int Y, int nWidth, int nHeight, bool bRepaint);     [DllImport("user32", CharSet = CharSet.Auto)] 
 public extern static IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);   
  private static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
  private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2); 
 private static readonly IntPtr HWND_TOP = new IntPtr(0); 
 private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);  
private static readonly UInt32 SWP_NOSIZE = 1;
  private static readonly UInt32 SWP_HIDEWINDOW = 128; 
 private static readonly Int32 WM_QUIT = 0x0012;  
private static readonly Int32 WM_HIDE = 0x0; 
//----------------------------------- private IntPtr _GEHrender; private IntPtr _GEParentHrender; private IntPtr _GEMainHandler; private IApplicationGE _googleEarth; private System.Windows.Forms.Control _parentControl;   /// <summary> /// 将GE的地图控件挂载到指定的控件中去 /// </summary> /// <param name="parentControl">c#控件</param> /// <param name="geApplication">ge应用程序</param> public void SetGEHandlerToControl(System.Windows.Forms.Control parentControl, IApplicationGE geApplication) { this._parentControl = parentControl; this._googleEarth = geApplication;   //获取GE的主窗体句柄 this._GEMainHandler = (IntPtr)this._googleEarth.GetMainHwnd(); //将GE主窗体的高宽设置为0,隐藏掉GE主窗体 SetWindowPos((int)this._GEMainHandler, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE + SWP_HIDEWINDOW);   //获取GE地图控件句柄 this._GEHrender = (IntPtr)_googleEarth.GetRenderHwnd(); //获取GE地图控件的父窗体句柄 this._GEParentHrender = GetParent(this._GEHrender); //将GE地图控件的父窗体设置为不可见 //(考虑到GE地图控件可能被其他程序截获,加上这一句以应万全) PostMessage((int)this._GEParentHrender, WM_HIDE, 0, 0);   //设置GE地图控件的父窗体句柄为winform上的控件 SetParent(this._GEHrender, parentControl.Handle); } //----------------------------------------------
//----------------------------------
  /// <summary>  /// 使GE控件的大小和父窗体的大小保持一致  /// </summary> 
 public void ResizeGEControl()  {   if (this._parentControl != null) 
  {    //设置GE地图控件的大小等于父窗体大小    
MoveWindow(this._GEHrender, 0, 0, this._parentControl.Width, this._parentControl.Height, true);   }  }  
   /// <summary>  /// 释放GE句柄  /// </summary> 
 public void RealseGEHandler()  {   try  
 {    if (this._parentControl != null)    {  
   //将GE地图控件的句柄还原到GE主窗体上去    
SetParent(this._GEHrender, this._GEParentHrender);    
 //关闭GE主程序    
 PostMessage(this._googleEarth.GetMainHwnd(), WM_QUIT, 0, 0);    }   }   finally   {  
  //为防本程序的进程不能成功退出而导致GE出现问题,强制杀掉本程序的进程  
  System.Diagnostics.Process geProcess = System.Diagnostics.Process.GetCurrentProcess();
    geProcess.Kill();   }  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值