通过调用Windows API隐藏GoogleEarth界面

网友投稿 237 2023-05-17

继《C#调用GoogleEarth Com API》,我又带给大家第二篇文章。这一篇文章在第一篇的基础上,展示如何调用Windows API隐藏GoogleEarth的界面,并将GoogleEarth的地图显示在自定义的窗体上。废话少说,直接上代码。

[[4987]]

1、主窗口代码:   

复制// 功能:GE实例(二) // 描述:GE COM API 网址:http://earth.google.com/comapi/index.html // 作者:温伟鹏 // 日期:2009-02-08 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using EARTHLib; namespace GEDemo { public partial class Form2 : Form { /// < summary> /// 用来关闭GoogleEarth的消息定义 /// < /summary> static readonly Int32 WM_QUIT = 0x0012; private IntPtr GEHWnd = (IntPtr)5; private IntPtr GEHrender = (IntPtr)5; private IntPtr GEParentHrender = (IntPtr)5; /// < summary> /// 定义GE应用程序类 /// < /summary> private ApplicationGEClass GeApp; public Form2() { InitializeComponent(); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!this.DesignMode) { GeApp = new ApplicationGEClass(); GEHWnd = (IntPtr)GeApp.GetMainHwnd(); NativeMethods.SetWindowPos(GEHWnd, NativeMethods.HWND_BOTTOM, 0, 0, 0, 0, NativeMethods.SWP_NOSIZE + NativeMethods.SWP_HIDEWINDOW); GEHrender = (IntPtr)GeApp.GetRenderHwnd(); GEParentHrender = (IntPtr)NativeMethods.GetParent(GEHrender); NativeMethods.MoveWindow(GEHrender, 0, 0, this.Width, this.Height, true); NativeMethods.SetParent(GEHrender, this.Handle); } } protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); NativeMethods.PostMessage(GeApp.GetMainHwnd(), WM_QUIT, 0, 0); } } }1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.

2、NativeMethods类定义:

复制// 功能:Windows API调用 // 描述:大家可以参照MSDN // 作者:温伟鹏 // 日期:2009-02-08 using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace GEDemo { public class NativeMethods { [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, UInt32 uflags); [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern IntPtr PostMessage(int hWnd, int msg, int wParam, int lParam); #region 预定义 public static readonly IntPtr HWND_BOTTOM = new IntPtr(1); public static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2); public static readonly IntPtr HWND_TOP = new IntPtr(0); public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); public static readonly UInt32 SWP_NOSIZE = 1; public static readonly UInt32 SWP_NOMOVE = 2; public static readonly UInt32 SWP_NOZORDER = 4; public static readonly UInt32 SWP_NOREDRAW = 8; public static readonly UInt32 SWP_NOACTIVATE = 16; public static readonly UInt32 SWP_FRAMECHANGED =32; public static readonly UInt32 SWP_SHOWWINDOW = 64; public static readonly UInt32 SWP_HIDEWINDOW = 128; public static readonly UInt32 SWP_NOCOPYBITS = 256; public static readonly UInt32 SWP_NOOWNERZORDER = 512; public static readonly UInt32 SWP_NOSENDCHANGING = 1024; #endregion public delegate int EnumWindowsProc(IntPtr hwnd, int lParam); [DllImport("user32", CharSet = CharSet.Auto)] public extern static IntPtr GetParent(IntPtr hWnd); [DllImport("user32", CharSet = CharSet.Auto)] public extern static bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); [DllImport("user32", CharSet = CharSet.Auto)] public extern static IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)] public static extern IntPtr GetWindow(IntPtr hWnd, int uCmd); public static int GW_CHILD = 5; public static int GW_HWNDNEXT = 2; } }1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.

3、执行效果: 

现在,调用Windows API隐藏GoogleEarth界面的效果就达到了。

【编辑推荐】

​​C#程序中的数据显 示:自定义标签和XML、XSL​​​​C#自定义事件是如何生成的​​​​C# 自定义控件dll文件的生成步骤​​​​C#自定义快捷键的实现​​​​C#自定义事件的步骤介绍​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:开发者必读!常用的二维码生成器 API 推荐
下一篇:分享我免费可用API接口网站
相关文章

 发表评论

暂时没有评论,来抢沙发吧~