using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; using System.Diagnostics; using EARTHLib; namespace map { public partial class Form1 : Form { [DllImport("user32.dll")] private static extern int SetParent(int hWndChild, int hWndParent); [DllImport("user32.dll")] private static extern bool ShowWindowAsync(int hWnd, int nCmdShow); [DllImport("user32.dll", SetLastError = true)] private static extern bool PostMessage(int hWnd, uint Msg, int wParam, int lParam); [DllImport("user32.dll", EntryPoint = "SetWindowPos")] private static extern bool SetWindowPos(int hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); [DllImport("user32.dll")] private static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam); private const int HWND_TOP = 0x0; private const int WM_COMMAND = 0x0112; private const int WM_QT_PAINT = 0xC2DC; private const int WM_PAINT = 0x000F; private const int WM_SIZE = 0x0015; private const int SWP_FRAMECHANGED = 0x0020; EARTHLib.ApplicationGE ge = new ApplicationGEClass(); public Form1() { InitializeComponent(); ShowWindowAsync(ge.GetMainHwnd(), 0); SetParent(ge.GetRenderHwnd(), this.Handle.ToInt32()); ResizeGoogleControl(); ge.OpenKmlFile(@"C:\map\test.kml", 0); } private void Form1_Resize(object sender, EventArgs e) { ResizeGoogleControl(); } private void ResizeGoogleControl() { SendMessage(ge.GetMainHwnd(), WM_COMMAND, WM_PAINT, 0); PostMessage(ge.GetMainHwnd(), WM_QT_PAINT, 0, 0); SetWindowPos(ge.GetMainHwnd(), HWND_TOP, 0, 0, (int)this.Width, (int)this.Height, SWP_FRAMECHANGED); SendMessage(ge.GetRenderHwnd(), WM_COMMAND, WM_SIZE, 0); } private void Form1_Load(object sender, EventArgs e) { } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { foreach (Process process in Process.GetProcesses()) { if (process.ProcessName.StartsWith("googleearth")) { process.Kill(); } } } } }