好久没有更新《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: }