本篇繼續介紹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: }