首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C# 呼叫 Google Earth COM API 開發(三):視窗自適應大小調整

     編輯:關於C語言

解決 Google Earth 嵌入控制項隨表單縮放而自動調整大小的問題,核心在於傳送 WM_COMMAND、WM_QT_PAINT、WM_SIZE 訊息並重新計算視窗矩形。

ResizeGoogleControl 方法

private void ResizeGoogleControl() {
    NativeMethods.SendMessage(GEHWnd, (uint)WM_COMMAND, WM_PAINT, 0);
    NativeMethods.PostMessage(GEHWnd, WM_QT_PAINT, 0, 0);

    RECT mainRect, clientRect;
    NativeMethods.GetWindowRect(GEHWnd, out mainRect);
    NativeMethods.GetClientRect(GEHrender, out clientRect);

    int offsetW = mainRect.Width - clientRect.Width;
    int offsetH = mainRect.Height - clientRect.Height;
    int newWidth = this.Control.Width + offsetW;
    int newHeight = this.Control.Height + offsetH;

    NativeMethods.SetWindowPos(GEHWnd, HWND_TOP, 0, 0, newWidth, newHeight, SWP_FRAMECHANGED);
    NativeMethods.SendMessage(GEHWnd, (uint)WM_COMMAND, WM_SIZE, 0);
}

此方法需在表單 Resize 事件中呼叫,確保 GE 畫面隨容器即時縮放。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved