為了將 Google Earth 視窗嵌入自訂表單,需要呼叫 Win32 API 操作視窗父子關係、位置大小。本文定義 NativeMethods 封裝常用 API。
public class NativeMethods {
[DllImport("user32.dll")] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
[DllImport("user32.dll")] public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll")] public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
// 常數定義:HWND_TOP, SWP_NOSIZE, SWP_NOZORDER 等...
}

此類別為後續視窗嵌入、調整大小、截圖等操作提供底層支援。