本篇继续介绍Google Earth COM API开发的基础知识,相对第三篇的改进如下:
1)增加鼠标滚轮支持,可以实现放大、缩小。此功能利用上一篇提供的HookAPI.dll实现
2)读取PlaceMarks(Google Earth界面中的位置)并显示、隐藏
3)读取所有图层,显示并隐藏
下面,继续放代码:
1、鼠标滚轮事件,实现放大、缩小
1: ...
2: // 放大
3: private const long ZoomIn = 0x00780000;
4: // 缩小
5: private const long ZoomOut = 0xFF880000;
6: ...
7: mouseHook.MouseWheel += new MouseEventHandler(mouseHook_MouseWheel);
8: ...
9: /// <summary>
10: /// 鼠标钩子。鼠标滚动事件
11: /// </summary>
12: /// <param name="sender"></param>
13: /// <param name="e"></param>
14: void mouseHook_MouseWheel(object sender, MouseEventArgs e)
15: {
16: IntPtr hWnd = NativeMethods.WindowFromPoint(e.Location);
17: if (hWnd == this.GeRenderHWnd)
18: {
19: Point point = this.Control.PointToClient(e.Location);
20: // 如果鼠标位置在控件内部,则说明鼠标在GoogleEarth视图范围内进行了滚动
21: if (this.Control.ClientRectangle.Contains(point))
22: {
23: NativeMethods.PostMessage(GeRenderHWnd, (int) WM_MOUSE.WM_MOUSEWHEEL, e.Delta == 120 ? ZoomIn : ZoomOut, 0);
24: }
25: }
26: }