好久沒有更新《C#調用Google Earth Com API開發》系列文章了,今天帶給大家的是第三篇,本篇相 對於第二篇主要改進了三個方面。
1) 實現GoogleEarth顯示畫面隨窗口大小改變而改變
2) 截獲GoogleEarth鼠標消息,實現單擊、雙擊功能;鼠標滾輪縮放現在只能放大!O(∩_∩)O~
3) 實現GoogleEarth彩色截圖(測試環境:Windows 2003 Server ,Vista與Win7中不可用,XP未測)
下面還是繼續看代碼:
1、GoogleEarth動態改變大小
1: /// <summary>
2: /// 重新改變GoogleEarth視圖的大小
3: /// </summary>
4: private void ResizeGoogleControl()
5: {
6: NativeMethods.SendMessage(GEHWnd, (uint)NativeMethods.WM_COMMAND, NativeMethods.WM_PAINT, 0);
7: NativeMethods.PostMessage(GEHWnd, NativeMethods.WM_QT_PAINT, 0, 0);
8:
9: RECT mainRect = new RECT();
10: NativeMethods.GetWindowRect(GEHWnd, out mainRect);
11: clIEntRect = new RECT();
12: NativeMethods.GetClientRect(GEHrender, out clIEntRect);
13:
14: int offsetW = mainRect.Width - clIEntRect.Width;
15: int offsetH = mainRect.Height - clIEntRect.Height;
16:
17: int newWidth = this.Control.Width + (int)offsetW;
18: int newHeight = this.Control.Height + (int)offsetH;
19:
20: NativeMethods.SetWindowPos(GEHWnd, NativeMethods.HWND_TOP,
21: 0, 0, newWidth, newHeight,
22: NativeMethods.SWP_FRAMECHANGED);
23:
24: NativeMethods.SendMessage(GEHWnd, (uint)NativeMethods.WM_COMMAND, NativeMethods.WM_SIZE, 0);
25: }