├── .gitattributes
├── .gitignore
├── GEDemo.sln
├── GEDemo1
├── GEDemo1.Designer.cs
├── GEDemo1.cs
├── GEDemo1.csproj
├── GEDemo1.resx
├── Program.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
└── app.config
├── GEDemo2
├── GEDemo2.Designer.cs
├── GEDemo2.cs
├── GEDemo2.csproj
├── GEDemo2.resx
├── NativeMethods.cs
├── Program.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
└── app.config
├── GEDemo3
├── GEDemo3.Designer.cs
├── GEDemo3.cs
├── GEDemo3.csproj
├── GEDemo3.resx
├── NativeMethods.cs
├── NativeStructure.cs
├── Program.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
└── app.config
├── GEDemo4
├── GEDemo4.Designer.cs
├── GEDemo4.cs
├── GEDemo4.csproj
├── GEDemo4.resx
├── NativeMethods.cs
├── NativeStructure.cs
├── Program.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── Resources
│ ├── GEApp.ico
│ ├── GEBgnd.jpg
│ ├── GESnap.jpg
│ └── GEStart.jpg
└── app.config
├── GEDemo5
├── GEDemo5.Designer.cs
├── GEDemo5.cs
├── GEDemo5.csproj
├── GEDemo5.resx
├── NativeMethods.cs
├── NativeStructure.cs
├── Program.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── Resources
│ ├── GEApp.ico
│ ├── GEBgnd.jpg
│ ├── GESnap.jpg
│ └── GEStart.jpg
└── app.config
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.sln.docstates
8 |
9 | # Build results
10 |
11 | [Dd]ebug/
12 | [Rr]elease/
13 | x64/
14 | build/
15 | [Bb]in/
16 | [Oo]bj/
17 |
18 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
19 | !packages/*/build/
20 |
21 | # MSTest test Results
22 | [Tt]est[Rr]esult*/
23 | [Bb]uild[Ll]og.*
24 |
25 | *_i.c
26 | *_p.c
27 | *.ilk
28 | *.meta
29 | *.obj
30 | *.pch
31 | *.pdb
32 | *.pgc
33 | *.pgd
34 | *.rsp
35 | *.sbr
36 | *.tlb
37 | *.tli
38 | *.tlh
39 | *.tmp
40 | *.tmp_proj
41 | *.log
42 | *.vspscc
43 | *.vssscc
44 | .builds
45 | *.pidb
46 | *.log
47 | *.scc
48 |
49 | # Visual C++ cache files
50 | ipch/
51 | *.aps
52 | *.ncb
53 | *.opensdf
54 | *.sdf
55 | *.cachefile
56 |
57 | # Visual Studio profiler
58 | *.psess
59 | *.vsp
60 | *.vspx
61 |
62 | # Guidance Automation Toolkit
63 | *.gpState
64 |
65 | # ReSharper is a .NET coding add-in
66 | _ReSharper*/
67 | *.[Rr]e[Ss]harper
68 |
69 | # TeamCity is a build add-in
70 | _TeamCity*
71 |
72 | # DotCover is a Code Coverage Tool
73 | *.dotCover
74 |
75 | # NCrunch
76 | *.ncrunch*
77 | .*crunch*.local.xml
78 |
79 | # Installshield output folder
80 | [Ee]xpress/
81 |
82 | # DocProject is a documentation generator add-in
83 | DocProject/buildhelp/
84 | DocProject/Help/*.HxT
85 | DocProject/Help/*.HxC
86 | DocProject/Help/*.hhc
87 | DocProject/Help/*.hhk
88 | DocProject/Help/*.hhp
89 | DocProject/Help/Html2
90 | DocProject/Help/html
91 |
92 | # Click-Once directory
93 | publish/
94 |
95 | # Publish Web Output
96 | *.Publish.xml
97 |
98 | # NuGet Packages Directory
99 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
100 | #packages/
101 |
102 | # Windows Azure Build Output
103 | csx
104 | *.build.csdef
105 |
106 | # Windows Store app package directory
107 | AppPackages/
108 |
109 | # Others
110 | sql/
111 | *.Cache
112 | ClientBin/
113 | [Ss]tyle[Cc]op.*
114 | ~$*
115 | *~
116 | *.dbmdl
117 | *.[Pp]ublish.xml
118 | *.pfx
119 | *.publishsettings
120 |
121 | # RIA/Silverlight projects
122 | Generated_Code/
123 |
124 | # Backup & report files from converting an old project file to a newer
125 | # Visual Studio version. Backup files are not needed, because we have git ;-)
126 | _UpgradeReport_Files/
127 | Backup*/
128 | UpgradeLog*.XML
129 | UpgradeLog*.htm
130 |
131 | # SQL Server files
132 | App_Data/*.mdf
133 | App_Data/*.ldf
134 |
135 |
136 | #LightSwitch generated files
137 | GeneratedArtifacts/
138 | _Pvt_Extensions/
139 | ModelManifest.xml
140 |
141 | # =========================
142 | # Windows detritus
143 | # =========================
144 |
145 | # Windows image file caches
146 | Thumbs.db
147 | ehthumbs.db
148 |
149 | # Folder config file
150 | Desktop.ini
151 |
152 | # Recycle Bin used on file shares
153 | $RECYCLE.BIN/
154 |
155 | # Mac desktop service store files
156 | .DS_Store
157 |
--------------------------------------------------------------------------------
/GEDemo.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.30501.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GEDemo1", "GEDemo1\GEDemo1.csproj", "{A0D768EE-F4A9-4AF4-9AA6-1FA4EB9F0B82}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GEDemo2", "GEDemo2\GEDemo2.csproj", "{9F97A194-0D87-4BCE-B8D8-067BF1975B83}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GEDemo3", "GEDemo3\GEDemo3.csproj", "{9D20FED2-6674-4645-AFC0-49B3F35E9A25}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GEDemo4", "GEDemo4\GEDemo4.csproj", "{52356277-5AF4-4978-8AAA-015EE94BD17C}"
13 | EndProject
14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GEDemo5", "GEDemo5\GEDemo5.csproj", "{CF675AD5-E0EF-415E-A120-A9340E5D24B4}"
15 | EndProject
16 | Global
17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
18 | Debug|Any CPU = Debug|Any CPU
19 | Debug|Mixed Platforms = Debug|Mixed Platforms
20 | Debug|x86 = Debug|x86
21 | Release|Any CPU = Release|Any CPU
22 | Release|Mixed Platforms = Release|Mixed Platforms
23 | Release|x86 = Release|x86
24 | EndGlobalSection
25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
26 | {A0D768EE-F4A9-4AF4-9AA6-1FA4EB9F0B82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {A0D768EE-F4A9-4AF4-9AA6-1FA4EB9F0B82}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {A0D768EE-F4A9-4AF4-9AA6-1FA4EB9F0B82}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
29 | {A0D768EE-F4A9-4AF4-9AA6-1FA4EB9F0B82}.Debug|Mixed Platforms.Build.0 = Debug|x86
30 | {A0D768EE-F4A9-4AF4-9AA6-1FA4EB9F0B82}.Debug|x86.ActiveCfg = Debug|x86
31 | {A0D768EE-F4A9-4AF4-9AA6-1FA4EB9F0B82}.Debug|x86.Build.0 = Debug|x86
32 | {A0D768EE-F4A9-4AF4-9AA6-1FA4EB9F0B82}.Release|Any CPU.ActiveCfg = Release|Any CPU
33 | {A0D768EE-F4A9-4AF4-9AA6-1FA4EB9F0B82}.Release|Any CPU.Build.0 = Release|Any CPU
34 | {A0D768EE-F4A9-4AF4-9AA6-1FA4EB9F0B82}.Release|Mixed Platforms.ActiveCfg = Release|x86
35 | {A0D768EE-F4A9-4AF4-9AA6-1FA4EB9F0B82}.Release|Mixed Platforms.Build.0 = Release|x86
36 | {A0D768EE-F4A9-4AF4-9AA6-1FA4EB9F0B82}.Release|x86.ActiveCfg = Release|x86
37 | {A0D768EE-F4A9-4AF4-9AA6-1FA4EB9F0B82}.Release|x86.Build.0 = Release|x86
38 | {9F97A194-0D87-4BCE-B8D8-067BF1975B83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39 | {9F97A194-0D87-4BCE-B8D8-067BF1975B83}.Debug|Any CPU.Build.0 = Debug|Any CPU
40 | {9F97A194-0D87-4BCE-B8D8-067BF1975B83}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
41 | {9F97A194-0D87-4BCE-B8D8-067BF1975B83}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
42 | {9F97A194-0D87-4BCE-B8D8-067BF1975B83}.Debug|x86.ActiveCfg = Debug|Any CPU
43 | {9F97A194-0D87-4BCE-B8D8-067BF1975B83}.Release|Any CPU.ActiveCfg = Release|Any CPU
44 | {9F97A194-0D87-4BCE-B8D8-067BF1975B83}.Release|Any CPU.Build.0 = Release|Any CPU
45 | {9F97A194-0D87-4BCE-B8D8-067BF1975B83}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
46 | {9F97A194-0D87-4BCE-B8D8-067BF1975B83}.Release|Mixed Platforms.Build.0 = Release|Any CPU
47 | {9F97A194-0D87-4BCE-B8D8-067BF1975B83}.Release|x86.ActiveCfg = Release|Any CPU
48 | {9D20FED2-6674-4645-AFC0-49B3F35E9A25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49 | {9D20FED2-6674-4645-AFC0-49B3F35E9A25}.Debug|Any CPU.Build.0 = Debug|Any CPU
50 | {9D20FED2-6674-4645-AFC0-49B3F35E9A25}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
51 | {9D20FED2-6674-4645-AFC0-49B3F35E9A25}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
52 | {9D20FED2-6674-4645-AFC0-49B3F35E9A25}.Debug|x86.ActiveCfg = Debug|Any CPU
53 | {9D20FED2-6674-4645-AFC0-49B3F35E9A25}.Release|Any CPU.ActiveCfg = Release|Any CPU
54 | {9D20FED2-6674-4645-AFC0-49B3F35E9A25}.Release|Any CPU.Build.0 = Release|Any CPU
55 | {9D20FED2-6674-4645-AFC0-49B3F35E9A25}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
56 | {9D20FED2-6674-4645-AFC0-49B3F35E9A25}.Release|Mixed Platforms.Build.0 = Release|Any CPU
57 | {9D20FED2-6674-4645-AFC0-49B3F35E9A25}.Release|x86.ActiveCfg = Release|Any CPU
58 | {52356277-5AF4-4978-8AAA-015EE94BD17C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
59 | {52356277-5AF4-4978-8AAA-015EE94BD17C}.Debug|Any CPU.Build.0 = Debug|Any CPU
60 | {52356277-5AF4-4978-8AAA-015EE94BD17C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
61 | {52356277-5AF4-4978-8AAA-015EE94BD17C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
62 | {52356277-5AF4-4978-8AAA-015EE94BD17C}.Debug|x86.ActiveCfg = Debug|Any CPU
63 | {52356277-5AF4-4978-8AAA-015EE94BD17C}.Release|Any CPU.ActiveCfg = Release|Any CPU
64 | {52356277-5AF4-4978-8AAA-015EE94BD17C}.Release|Any CPU.Build.0 = Release|Any CPU
65 | {52356277-5AF4-4978-8AAA-015EE94BD17C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
66 | {52356277-5AF4-4978-8AAA-015EE94BD17C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
67 | {52356277-5AF4-4978-8AAA-015EE94BD17C}.Release|x86.ActiveCfg = Release|Any CPU
68 | {CF675AD5-E0EF-415E-A120-A9340E5D24B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
69 | {CF675AD5-E0EF-415E-A120-A9340E5D24B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
70 | {CF675AD5-E0EF-415E-A120-A9340E5D24B4}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
71 | {CF675AD5-E0EF-415E-A120-A9340E5D24B4}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
72 | {CF675AD5-E0EF-415E-A120-A9340E5D24B4}.Debug|x86.ActiveCfg = Debug|Any CPU
73 | {CF675AD5-E0EF-415E-A120-A9340E5D24B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
74 | {CF675AD5-E0EF-415E-A120-A9340E5D24B4}.Release|Any CPU.Build.0 = Release|Any CPU
75 | {CF675AD5-E0EF-415E-A120-A9340E5D24B4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
76 | {CF675AD5-E0EF-415E-A120-A9340E5D24B4}.Release|Mixed Platforms.Build.0 = Release|Any CPU
77 | {CF675AD5-E0EF-415E-A120-A9340E5D24B4}.Release|x86.ActiveCfg = Release|Any CPU
78 | EndGlobalSection
79 | GlobalSection(SolutionProperties) = preSolution
80 | HideSolutionNode = FALSE
81 | EndGlobalSection
82 | EndGlobal
83 |
--------------------------------------------------------------------------------
/GEDemo1/GEDemo1.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace GEDemo1
2 | {
3 | partial class GEDemo1
4 | {
5 | ///
6 | /// 必需的设计器变量。
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// 清理所有正在使用的资源。
12 | ///
13 | /// 如果应释放托管资源,为 true;否则为 false。
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows 窗体设计器生成的代码
24 |
25 | ///
26 | /// 设计器支持所需的方法 - 不要
27 | /// 使用代码编辑器修改此方法的内容。
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.button1 = new System.Windows.Forms.Button();
32 | this.button2 = new System.Windows.Forms.Button();
33 | this.button3 = new System.Windows.Forms.Button();
34 | this.pictureBox1 = new System.Windows.Forms.PictureBox();
35 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
36 | this.SuspendLayout();
37 | //
38 | // button1
39 | //
40 | this.button1.Location = new System.Drawing.Point(13, 513);
41 | this.button1.Name = "button1";
42 | this.button1.Size = new System.Drawing.Size(90, 38);
43 | this.button1.TabIndex = 0;
44 | this.button1.Text = "启动";
45 | this.button1.UseVisualStyleBackColor = true;
46 | this.button1.Click += new System.EventHandler(this.button1_Click);
47 | //
48 | // button2
49 | //
50 | this.button2.Location = new System.Drawing.Point(419, 513);
51 | this.button2.Name = "button2";
52 | this.button2.Size = new System.Drawing.Size(90, 38);
53 | this.button2.TabIndex = 1;
54 | this.button2.Text = "截图";
55 | this.button2.UseVisualStyleBackColor = true;
56 | this.button2.Click += new System.EventHandler(this.button2_Click);
57 | //
58 | // button3
59 | //
60 | this.button3.Location = new System.Drawing.Point(798, 513);
61 | this.button3.Name = "button3";
62 | this.button3.Size = new System.Drawing.Size(90, 38);
63 | this.button3.TabIndex = 3;
64 | this.button3.Text = "退出";
65 | this.button3.UseVisualStyleBackColor = true;
66 | this.button3.Click += new System.EventHandler(this.button3_Click);
67 | //
68 | // pictureBox1
69 | //
70 | this.pictureBox1.Location = new System.Drawing.Point(13, 13);
71 | this.pictureBox1.Name = "pictureBox1";
72 | this.pictureBox1.Size = new System.Drawing.Size(875, 494);
73 | this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
74 | this.pictureBox1.TabIndex = 4;
75 | this.pictureBox1.TabStop = false;
76 | //
77 | // GEDemo1
78 | //
79 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
80 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
81 | this.ClientSize = new System.Drawing.Size(900, 563);
82 | this.Controls.Add(this.pictureBox1);
83 | this.Controls.Add(this.button3);
84 | this.Controls.Add(this.button2);
85 | this.Controls.Add(this.button1);
86 | this.Name = "GEDemo1";
87 | this.Text = "GEDemo1";
88 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
89 | this.ResumeLayout(false);
90 |
91 | }
92 |
93 | #endregion
94 |
95 | private System.Windows.Forms.Button button1;
96 | private System.Windows.Forms.Button button2;
97 | private System.Windows.Forms.Button button3;
98 | private System.Windows.Forms.PictureBox pictureBox1;
99 | }
100 | }
101 |
102 |
--------------------------------------------------------------------------------
/GEDemo1/GEDemo1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 | using System.Windows.Forms;
4 | using System.Runtime.InteropServices;
5 | using EARTHLib;
6 | using System.IO;
7 | using System.Diagnostics;
8 |
9 | namespace GEDemo1
10 | {
11 | public partial class GEDemo1 : Form
12 | {
13 | private bool isGEStarted = false;
14 | private ApplicationGE GEApp;
15 | private string ssFile;
16 | public GEDemo1()
17 | {
18 | InitializeComponent();
19 | }
20 |
21 | private void StartGE()
22 | {
23 | if (isGEStarted)
24 | {
25 | return;
26 | }
27 |
28 | try
29 | {
30 | //启动GE
31 | GEApp = (ApplicationGEClass)Marshal.GetActiveObject("GoogleEarth.Application");
32 |
33 | isGEStarted = true;
34 | }
35 | catch
36 | {
37 | GEApp = new ApplicationGEClass();
38 |
39 | isGEStarted = true;
40 | }
41 | }
42 |
43 | private void button1_Click(object sender, EventArgs e)
44 | {
45 | StartGE();
46 | }
47 |
48 | private void button2_Click(object sender, EventArgs e)
49 | {
50 | ssFile = Path.Combine(Application.StartupPath, System.DateTime.Now.ToString("GES_yyyyMMddHHmmss")+".jpg");
51 |
52 | try
53 | {
54 | //quality的取值范围在(0,100)之间,质量越高,quality越大
55 | GEApp.SaveScreenShot(ssFile, 100);
56 |
57 | //载入刚才的图像
58 | pictureBox1.Image = Bitmap.FromFile(ssFile);
59 | }
60 | catch (Exception ex)
61 | {
62 | MessageBox.Show("保存截屏图像时发生错误:" + ex.ToString());
63 | }
64 | }
65 |
66 | private void button3_Click(object sender, EventArgs e)
67 | {
68 | //首先杀掉GoogleEarth进程
69 | Process[] geProcess = Process.GetProcessesByName("GoogleEarth");
70 | foreach (var p in geProcess)
71 | {
72 | p.Kill();
73 | }
74 |
75 | //然后关闭窗口,退出程序
76 | this.Close();
77 | Application.Exit();
78 | }
79 |
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/GEDemo1/GEDemo1.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {A0D768EE-F4A9-4AF4-9AA6-1FA4EB9F0B82}
8 | WinExe
9 | Properties
10 | GEDemo1
11 | GEDemo1
12 | v2.0
13 | 512
14 |
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | ..\bin\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 | true
37 | bin\x86\Debug\
38 | DEBUG;TRACE
39 | full
40 | x86
41 | prompt
42 | MinimumRecommendedRules.ruleset
43 |
44 |
45 | ..\bin\
46 | TRACE
47 | true
48 | pdbonly
49 | x86
50 | prompt
51 | MinimumRecommendedRules.ruleset
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | Form
64 |
65 |
66 | GEDemo1.cs
67 |
68 |
69 |
70 |
71 | GEDemo1.cs
72 |
73 |
74 | ResXFileCodeGenerator
75 | Resources.Designer.cs
76 | Designer
77 |
78 |
79 | True
80 | Resources.resx
81 | True
82 |
83 |
84 |
85 | SettingsSingleFileGenerator
86 | Settings.Designer.cs
87 |
88 |
89 | True
90 | Settings.settings
91 | True
92 |
93 |
94 |
95 |
96 | {3476FAB2-687F-4EA6-9AC2-88D72DC7D7FC}
97 | 1
98 | 0
99 | 0
100 | tlbimp
101 | False
102 | True
103 |
104 |
105 | {00020430-0000-0000-C000-000000000046}
106 | 2
107 | 0
108 | 0
109 | primary
110 | False
111 | True
112 |
113 |
114 |
115 |
122 |
--------------------------------------------------------------------------------
/GEDemo1/GEDemo1.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/GEDemo1/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows.Forms;
4 |
5 | namespace GEDemo1
6 | {
7 | static class Program
8 | {
9 | ///
10 | /// 应用程序的主入口点。
11 | ///
12 | [STAThread]
13 | static void Main()
14 | {
15 | Application.EnableVisualStyles();
16 | Application.SetCompatibleTextRenderingDefault(false);
17 | Application.Run(new GEDemo1());
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/GEDemo1/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("GEDemo1")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("GEDemo1")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("3e95c7c7-0201-48ce-b710-15b4d65dd59c")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/GEDemo1/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.18408
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace GEDemo1.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// 一个强类型的资源类,用于查找本地化的字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// 返回此类使用的缓存的 ResourceManager 实例。
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GEDemo1.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// 使用此强类型资源类,为所有资源查找
51 | /// 重写当前线程的 CurrentUICulture 属性。
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/GEDemo1/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/GEDemo1/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.18408
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace GEDemo1.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/GEDemo1/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/GEDemo1/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/GEDemo2/GEDemo2.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace GEDemo2
2 | {
3 | partial class GEDemo2
4 | {
5 | ///
6 | /// 必需的设计器变量。
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// 清理所有正在使用的资源。
12 | ///
13 | /// 如果应释放托管资源,为 true;否则为 false。
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows 窗体设计器生成的代码
24 |
25 | ///
26 | /// 设计器支持所需的方法 - 不要
27 | /// 使用代码编辑器修改此方法的内容。
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.SuspendLayout();
32 | //
33 | // GEDemo2
34 | //
35 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
36 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
37 | this.ClientSize = new System.Drawing.Size(1100, 820);
38 | this.Name = "GEDemo2";
39 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
40 | this.Text = "GEDemo2";
41 | this.ResumeLayout(false);
42 |
43 | }
44 |
45 | #endregion
46 | }
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/GEDemo2/GEDemo2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Text;
7 | using System.Windows.Forms;
8 | using EARTHLib;
9 |
10 | namespace GEDemo2
11 | {
12 | public partial class GEDemo2 : Form
13 | {
14 | static readonly Int32 WM_QUIT = 0x0012;
15 | private IntPtr GEHMainWnd = (IntPtr)0;
16 | private IntPtr GEHRenderWnd = (IntPtr)0;
17 |
18 | private ApplicationGE GEApp;
19 | public GEDemo2()
20 | {
21 | InitializeComponent();
22 | }
23 |
24 | //重写OnLoad比实现Form_Load更高效
25 | protected override void OnLoad(EventArgs e)
26 | {
27 | base.OnLoad(e);
28 |
29 | //启动GoogleEarth实例
30 | GEApp = new ApplicationGE();
31 |
32 | GEHMainWnd = (IntPtr)GEApp.GetMainHwnd();
33 | //隐藏GoogleEarth主窗口
34 | NativeMethods.SetWindowPos(GEHMainWnd, NativeMethods.HWND_BOTTOM,
35 | 0, 0, 0, 0,
36 | NativeMethods.SWP_NOSIZE | NativeMethods.SWP_HIDEWINDOW);
37 |
38 | GEHRenderWnd = (IntPtr)GEApp.GetRenderHwnd();
39 | //将渲染窗口嵌入到主窗体
40 | NativeMethods.MoveWindow(GEHRenderWnd, 0, 0, this.Width, this.Height, true);
41 | NativeMethods.SetParent(GEHRenderWnd, this.Handle);
42 | }
43 |
44 | protected override void OnClosing(CancelEventArgs e)
45 | {
46 | base.OnClosing(e);
47 |
48 | //关闭窗口
49 | NativeMethods.PostMessage((int)GEHMainWnd, WM_QUIT, 0, 0);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/GEDemo2/GEDemo2.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {9F97A194-0D87-4BCE-B8D8-067BF1975B83}
8 | WinExe
9 | Properties
10 | GEDemo2
11 | GEDemo2
12 | v2.0
13 | 512
14 |
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | x86
28 | pdbonly
29 | true
30 | ..\bin\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | Form
46 |
47 |
48 | GEDemo2.cs
49 |
50 |
51 |
52 |
53 |
54 | GEDemo2.cs
55 |
56 |
57 | ResXFileCodeGenerator
58 | Resources.Designer.cs
59 | Designer
60 |
61 |
62 | True
63 | Resources.resx
64 | True
65 |
66 |
67 |
68 | SettingsSingleFileGenerator
69 | Settings.Designer.cs
70 |
71 |
72 | True
73 | Settings.settings
74 | True
75 |
76 |
77 |
78 |
79 | {3476FAB2-687F-4EA6-9AC2-88D72DC7D7FC}
80 | 1
81 | 0
82 | 0
83 | tlbimp
84 | False
85 | True
86 |
87 |
88 | {00020430-0000-0000-C000-000000000046}
89 | 2
90 | 0
91 | 0
92 | primary
93 | False
94 | True
95 |
96 |
97 |
98 |
105 |
--------------------------------------------------------------------------------
/GEDemo2/GEDemo2.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/GEDemo2/NativeMethods.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengyhack/LearningGoogleEarthNET/4a3c04ecc754385e56e5b1cb24e37aed835de6b9/GEDemo2/NativeMethods.cs
--------------------------------------------------------------------------------
/GEDemo2/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows.Forms;
4 |
5 | namespace GEDemo2
6 | {
7 | static class Program
8 | {
9 | ///
10 | /// 应用程序的主入口点。
11 | ///
12 | [STAThread]
13 | static void Main()
14 | {
15 | Application.EnableVisualStyles();
16 | Application.SetCompatibleTextRenderingDefault(false);
17 | Application.Run(new GEDemo2());
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/GEDemo2/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("GEDemo2")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("GEDemo2")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("981a7d1f-219d-4ce2-99a9-7fb163f5da87")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/GEDemo2/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.18408
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace GEDemo2.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// 一个强类型的资源类,用于查找本地化的字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// 返回此类使用的缓存的 ResourceManager 实例。
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GEDemo2.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// 使用此强类型资源类,为所有资源查找
51 | /// 重写当前线程的 CurrentUICulture 属性。
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/GEDemo2/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/GEDemo2/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.18408
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace GEDemo2.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/GEDemo2/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/GEDemo2/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/GEDemo3/GEDemo3.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace GEDemo3
2 | {
3 | partial class GEDemo3
4 | {
5 | ///
6 | /// 必需的设计器变量。
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// 清理所有正在使用的资源。
12 | ///
13 | /// 如果应释放托管资源,为 true;否则为 false。
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows 窗体设计器生成的代码
24 |
25 | ///
26 | /// 设计器支持所需的方法 - 不要
27 | /// 使用代码编辑器修改此方法的内容。
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.components = new System.ComponentModel.Container();
32 | this.tabControl1 = new System.Windows.Forms.TabControl();
33 | this.tabPage1 = new System.Windows.Forms.TabPage();
34 | this.button3 = new System.Windows.Forms.Button();
35 | this.button2 = new System.Windows.Forms.Button();
36 | this.button1 = new System.Windows.Forms.Button();
37 | this.tabPage2 = new System.Windows.Forms.TabPage();
38 | this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
39 | this.setCameraParameters = new System.Windows.Forms.GroupBox();
40 | this.tabControl1.SuspendLayout();
41 | this.tabPage1.SuspendLayout();
42 | this.setCameraParameters.SuspendLayout();
43 | this.SuspendLayout();
44 | //
45 | // tabControl1
46 | //
47 | this.tabControl1.Controls.Add(this.tabPage1);
48 | this.tabControl1.Controls.Add(this.tabPage2);
49 | this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
50 | this.tabControl1.Location = new System.Drawing.Point(0, 0);
51 | this.tabControl1.Name = "tabControl1";
52 | this.tabControl1.SelectedIndex = 0;
53 | this.tabControl1.Size = new System.Drawing.Size(1100, 800);
54 | this.tabControl1.TabIndex = 0;
55 | //
56 | // tabPage1
57 | //
58 | this.tabPage1.AutoScroll = true;
59 | this.tabPage1.AutoScrollMinSize = new System.Drawing.Size(1000, 750);
60 | this.tabPage1.BackColor = System.Drawing.SystemColors.Control;
61 | this.tabPage1.Controls.Add(this.setCameraParameters);
62 | this.tabPage1.Location = new System.Drawing.Point(4, 25);
63 | this.tabPage1.Name = "tabPage1";
64 | this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
65 | this.tabPage1.Size = new System.Drawing.Size(100, 800);
66 | this.tabPage1.TabIndex = 0;
67 | this.tabPage1.Text = "GEViewer";
68 | //
69 | // button3
70 | //
71 | this.button3.Location = new System.Drawing.Point(500, 24);
72 | this.button3.Name = "button3";
73 | this.button3.Size = new System.Drawing.Size(106, 36);
74 | this.button3.TabIndex = 2;
75 | this.button3.Text = "查看截图";
76 | this.button3.UseVisualStyleBackColor = true;
77 | this.button3.Click += new System.EventHandler(this.button3_Click);
78 | //
79 | // button2
80 | //
81 | this.button2.Location = new System.Drawing.Point(242, 24);
82 | this.button2.Name = "button2";
83 | this.button2.Size = new System.Drawing.Size(140, 36);
84 | this.button2.TabIndex = 1;
85 | this.button2.Text = "WinAPI截图";
86 | this.button2.UseVisualStyleBackColor = true;
87 | this.button2.Click += new System.EventHandler(this.button2_Click);
88 | //
89 | // button1
90 | //
91 | this.button1.Location = new System.Drawing.Point(26, 24);
92 | this.button1.Name = "button1";
93 | this.button1.Size = new System.Drawing.Size(140, 36);
94 | this.button1.TabIndex = 0;
95 | this.button1.Text = "GE截图(Gray)";
96 | this.button1.UseVisualStyleBackColor = true;
97 | this.button1.Click += new System.EventHandler(this.button1_Click);
98 | //
99 | // tabPage2
100 | //
101 | this.tabPage2.BackColor = System.Drawing.SystemColors.Control;
102 | this.tabPage2.Location = new System.Drawing.Point(4, 25);
103 | this.tabPage2.Name = "tabPage2";
104 | this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
105 | this.tabPage2.Size = new System.Drawing.Size(1191, 862);
106 | this.tabPage2.TabIndex = 1;
107 | this.tabPage2.Text = "Snapshot";
108 | //
109 | // setCameraParameters
110 | //
111 | this.setCameraParameters.Controls.Add(this.button1);
112 | this.setCameraParameters.Controls.Add(this.button3);
113 | this.setCameraParameters.Controls.Add(this.button2);
114 | this.setCameraParameters.Dock = System.Windows.Forms.DockStyle.Bottom;
115 | this.setCameraParameters.Location = new System.Drawing.Point(3, 791);
116 | this.setCameraParameters.Name = "setCameraParameters";
117 | this.setCameraParameters.Size = new System.Drawing.Size(1185, 68);
118 | this.setCameraParameters.TabIndex = 3;
119 | this.setCameraParameters.TabStop = false;
120 | //
121 | // GEDemo3
122 | //
123 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
124 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
125 | this.ClientSize = new System.Drawing.Size(1199, 891);
126 | this.Controls.Add(this.tabControl1);
127 | this.Name = "GEDemo3";
128 | this.Text = "GEDemo3";
129 | this.tabControl1.ResumeLayout(false);
130 | this.tabPage1.ResumeLayout(false);
131 | this.setCameraParameters.ResumeLayout(false);
132 | this.ResumeLayout(false);
133 |
134 | }
135 |
136 | #endregion
137 |
138 | private System.Windows.Forms.TabControl tabControl1;
139 | private System.Windows.Forms.TabPage tabPage1;
140 | private System.Windows.Forms.TabPage tabPage2;
141 | private System.Windows.Forms.Button button1;
142 | private System.Windows.Forms.Button button3;
143 | private System.Windows.Forms.Button button2;
144 | private System.Windows.Forms.ToolTip toolTip1;
145 | private System.Windows.Forms.GroupBox setCameraParameters;
146 | }
147 | }
148 |
149 |
--------------------------------------------------------------------------------
/GEDemo3/GEDemo3.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 | using System.ComponentModel;
4 | using EARTHLib;
5 | using System.Drawing;
6 | using System.Drawing.Imaging;
7 |
8 |
9 | namespace GEDemo3
10 | {
11 | public partial class GEDemo3 : Form
12 | {
13 | static readonly Int32 WM_QUIT = 0x0012;
14 | private IntPtr GEHMainWnd = (IntPtr)0;
15 | private IntPtr GEHRenderWnd = (IntPtr)0;
16 |
17 | private ApplicationGE GEApp;
18 | public GEDemo3()
19 | {
20 | InitializeComponent();
21 | }
22 |
23 | //重写OnLoad比实现Form_Load更高效
24 | protected override void OnLoad(EventArgs e)
25 | {
26 | base.OnLoad(e);
27 |
28 | //启动GoogleEarth实例
29 | GEApp = new ApplicationGE();
30 |
31 | GEHMainWnd = (IntPtr)GEApp.GetMainHwnd();
32 | //隐藏GoogleEarth主窗口
33 | NativeMethods.SetWindowPos(GEHMainWnd, NativeMethods.HWND_BOTTOM,
34 | 0, 0, 0, 0,
35 | NativeMethods.SWP_NOSIZE | NativeMethods.SWP_HIDEWINDOW);
36 |
37 | GEHRenderWnd = (IntPtr)GEApp.GetRenderHwnd();
38 | //将渲染窗口嵌入到主窗体
39 | NativeMethods.MoveWindow(GEHRenderWnd, 2, 2, tabPage1.Width - 20, tabPage1.Height - 20, true);
40 | NativeMethods.SetParent(GEHRenderWnd, tabPage1.Handle);
41 | }
42 |
43 | protected override void OnClosing(CancelEventArgs e)
44 | {
45 | base.OnClosing(e);
46 |
47 | //关闭窗口
48 | NativeMethods.PostMessage(GEHMainWnd, WM_QUIT, 0, 0);
49 | }
50 |
51 | protected override void OnSizeChanged(EventArgs e)
52 | {
53 | base.OnSizeChanged(e);
54 | ResizeGERenderViewer();
55 | }
56 |
57 | private void ResizeGERenderViewer()
58 | {
59 | NativeMethods.SendMessage(GEHMainWnd, (uint)NativeMethods.WM_COMMAND, NativeMethods.WM_PAINT, 0);
60 | NativeMethods.PostMessage(GEHMainWnd, NativeMethods.WM_QT_PAINT, 0, 0);
61 |
62 | RECT mainRect = new RECT();
63 | NativeMethods.GetWindowRect(GEHMainWnd, out mainRect);
64 | int left = (tabPage1.Width - mainRect.width) / 2;
65 | int top = (tabPage1.Height - mainRect.height) / 2;
66 |
67 | NativeMethods.SetWindowPos(GEHMainWnd, NativeMethods.HWND_TOP,
68 | left, top, mainRect.width, mainRect.height, NativeMethods.SWP_FRAMECHANGED);
69 |
70 | NativeMethods.SendMessage(GEHMainWnd, (uint)NativeMethods.WM_COMMAND, NativeMethods.WM_SIZE, 0);
71 | }
72 |
73 | private void button1_Click(object sender, EventArgs e)
74 | {
75 | if (GEApp != null && GEApp.IsInitialized() > 0)
76 | {
77 | using (SaveFileDialog sfd = new SaveFileDialog())
78 | {
79 | sfd.Filter = "JPEG图片(*.jpg)|*.jpg";
80 | sfd.AddExtension = true;
81 | sfd.CheckPathExists = true;
82 | sfd.Title = "保存Google Earth截图";
83 |
84 | if (sfd.ShowDialog() == DialogResult.OK)
85 | {
86 | GEApp.SaveScreenShot(sfd.FileName, 100);
87 | toolTip1.Show("\'"+sfd.FileName + "\' Saved", tabPage1, 300, 200, 2000);
88 | }
89 | }
90 | }
91 | }
92 |
93 | private void button2_Click(object sender, EventArgs e)
94 | {
95 | RECT rect = new RECT();
96 | NativeMethods.GetClientRect(GEHRenderWnd, out rect);
97 |
98 | if (GEHRenderWnd != IntPtr.Zero)
99 | {
100 | // 取得Render DC
101 | IntPtr hRenderDC = NativeMethods.GetWindowDC(GEHRenderWnd);
102 | // 创建hBitmap
103 | IntPtr hBitmap = NativeMethods.CreateCompatibleBitmap(hRenderDC, rect.width, rect.height);
104 | // 创建MEM DC
105 | IntPtr hMemDC = NativeMethods.CreateCompatibleDC(hRenderDC);
106 | // 将Bitmap Select到MemDC
107 | NativeMethods.SelectObject(hMemDC, hBitmap);
108 | // 直接拷屏
109 | NativeMethods.BitBlt(hMemDC, 0, 0, rect.width, rect.height,
110 | hRenderDC, 0, 0, 13369376);
111 |
112 | using (Bitmap bmp = Bitmap.FromHbitmap(hBitmap))
113 | {
114 | using (SaveFileDialog sfd = new SaveFileDialog())
115 | {
116 | sfd.Filter = "JPEG图片(*.jpg)|*.jpg|PNG图片(*.png)|*.png";
117 | sfd.AddExtension = true;
118 | sfd.CheckPathExists = true;
119 | sfd.Title = "保存Google Earth截图";
120 |
121 | if (sfd.ShowDialog() == DialogResult.OK)
122 | {
123 | ImageFormat imgFormat = null;
124 | // 默认选择JPG
125 | if (sfd.FilterIndex == 0)
126 | {
127 | imgFormat = ImageFormat.Jpeg;
128 | }
129 | // 选择PNG
130 | else
131 | {
132 | imgFormat = ImageFormat.Png;
133 | }
134 | bmp.Save(sfd.FileName, imgFormat);
135 | toolTip1.Show("\'" + sfd.FileName + "\' Saved", tabPage1, 300, 200, 2000);
136 | }
137 | }
138 |
139 | //销毁资源
140 | NativeMethods.DeleteDC(hRenderDC);
141 | NativeMethods.DeleteDC(hMemDC);
142 | }
143 | }
144 | }
145 |
146 | private void button3_Click(object sender, EventArgs e)
147 | {
148 |
149 | }
150 |
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/GEDemo3/GEDemo3.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {9D20FED2-6674-4645-AFC0-49B3F35E9A25}
8 | WinExe
9 | Properties
10 | GEDemo3
11 | GEDemo3
12 | v2.0
13 | 512
14 |
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | x86
28 | pdbonly
29 | true
30 | ..\bin\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | Form
46 |
47 |
48 | GEDemo3.cs
49 |
50 |
51 |
52 |
53 |
54 |
55 | GEDemo3.cs
56 |
57 |
58 | ResXFileCodeGenerator
59 | Resources.Designer.cs
60 | Designer
61 |
62 |
63 | True
64 | Resources.resx
65 | True
66 |
67 |
68 |
69 | SettingsSingleFileGenerator
70 | Settings.Designer.cs
71 |
72 |
73 | True
74 | Settings.settings
75 | True
76 |
77 |
78 |
79 |
80 | {3476FAB2-687F-4EA6-9AC2-88D72DC7D7FC}
81 | 1
82 | 0
83 | 0
84 | tlbimp
85 | False
86 | True
87 |
88 |
89 | {00020430-0000-0000-C000-000000000046}
90 | 2
91 | 0
92 | 0
93 | primary
94 | False
95 | True
96 |
97 |
98 |
99 |
106 |
--------------------------------------------------------------------------------
/GEDemo3/GEDemo3.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | 17, 17
122 |
123 |
--------------------------------------------------------------------------------
/GEDemo3/NativeMethods.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 | using System.Runtime.InteropServices;
4 | using System.Drawing;
5 |
6 | namespace GEDemo3
7 | {
8 | public class NativeMethods
9 | {
10 | [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
11 | public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, UInt32 uflags);
12 |
13 | [DllImport("user32.dll", CharSet = CharSet.Auto)]
14 | public static extern IntPtr PostMessage(IntPtr hWnd, int msg, int wParam, int lParam);
15 | [DllImport("user32.dll")]
16 | public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
17 | [DllImport("user32.dll", CharSet = CharSet.Auto)]
18 | public static extern int GetMessage(out MSG msg, IntPtr hWnd, int wMsgFilterMin, int wMsgFilterMax);
19 | [DllImport("user32.dll", CharSet = CharSet.Auto)]
20 | public static extern int PeekMessage(out MSG msg, IntPtr hWnd, int wMsgFilterMin, int wMsgFilterMax);
21 | [DllImport("user32.dll", CharSet = CharSet.Auto)]
22 | public static extern long DispatchMessage(MSG msg);
23 |
24 | [DllImport("user32.dll")]
25 | public static extern IntPtr FindWindow(string className, string windowTitle);
26 | [DllImport("user32.dll")]
27 | public static extern bool ShowWindowAsync(int hWnd, int nCmdShow);
28 |
29 | [DllImport("user32.dll")]
30 | public static extern bool GetWindowRect(IntPtr hWnd, out RECT rect);
31 |
32 | [DllImport("user32.dll")]
33 | public static extern bool GetClientRect(IntPtr hWnd, out RECT rect);
34 |
35 | [DllImport("user32.dll")]
36 | public static extern IntPtr GetDesktopWindow();
37 |
38 | [DllImport("user32")]
39 | public static extern IntPtr GetWindowDC(IntPtr hwnd);
40 |
41 | [DllImport("user32")]
42 | public static extern IntPtr GetDC(IntPtr hwnd);
43 |
44 | [DllImport("user32")]
45 | public static extern long ReleaseDC(IntPtr handle, IntPtr hdc);
46 |
47 | [DllImport("user32")]
48 | public static extern IntPtr WindowFromPoint(Point point);
49 |
50 | [DllImport("user32")]
51 | public static extern bool PrintWindow(IntPtr hWnd, IntPtr hdcBlt, UInt32 nFlags);
52 |
53 | [DllImport("kernel32.dll", SetLastError = true)]
54 | [return: MarshalAs(UnmanagedType.Bool)]
55 | public static extern bool CloseHandle(IntPtr hObject);
56 |
57 | #region 预定义
58 |
59 | public static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
60 | public static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
61 | public static readonly IntPtr HWND_TOP = new IntPtr(0);
62 | public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
63 | public static readonly uint SWP_NOSIZE = 1U;
64 | public static readonly uint SWP_NOMOVE = 2U;
65 | public static readonly uint SWP_NOZORDER = 4U;
66 | public static readonly uint SWP_NOREDRAW = 8U;
67 | public static readonly uint SWP_NOACTIVATE = 16U;
68 | public static readonly uint SWP_FRAMECHANGED = 32U;
69 | public static readonly uint SWP_SHOWWINDOW = 64U;
70 | public static readonly uint SWP_HIDEWINDOW = 128U;
71 | public static readonly uint SWP_NOCOPYBITS = 256U;
72 | public static readonly uint SWP_NOOWNERZORDER = 512U;
73 | public static readonly uint SWP_NOSENDCHANGING = 1024U;
74 | public static readonly int WM_COMMAND = 0x0112;
75 | public static readonly int WM_QT_PAINT = 0xC2DC;
76 | public static readonly int WM_PAINT = 0x000F;
77 | public static readonly int WM_SIZE = 0x0005;
78 |
79 | #endregion
80 |
81 | public delegate int EnumWindowsProc(IntPtr hWnd, int lParam);
82 |
83 | [DllImport("user32", CharSet = CharSet.Auto)]
84 | public extern static IntPtr GetParent(IntPtr hWnd);
85 |
86 | [DllImport("user32", CharSet = CharSet.Auto)]
87 | public extern static bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
88 |
89 | [DllImport("user32", CharSet = CharSet.Auto)]
90 | public extern static IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
91 |
92 | [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
93 | public static extern IntPtr GetWindow(IntPtr hWnd, int uCmd);
94 |
95 | public static int GW_CHILD = 5;
96 | public static int GW_HWNDNEXT = 2;
97 |
98 | #region GDI绘图函数
99 |
100 | [DllImport("gdi32.dll")]
101 | public static extern IntPtr CreateCompatibleDC(IntPtr hwnd);
102 |
103 | [DllImport("gdi32.dll")]
104 | public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidht, int nHeight);
105 |
106 | [DllImport("gdi32.dll")]
107 | public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
108 |
109 | [DllImport("gdi32.dll")]
110 | public static extern int DeleteDC(IntPtr hdc);
111 |
112 | [DllImport("gdi32.dll")]
113 | public static extern IntPtr CreateDC(string lpszDriver, string lpszDevice, string lpszOutput, IntPtr lpInitData);
114 | ///
115 | /// API函数BitBlt
116 | ///
117 | /// DC目标设备句柄
118 | /// 目标对象的左上角X坐标
119 | /// 目标对象的左上角Y坐标
120 | /// 目标对象的矩形宽度
121 | /// 目标对象的矩形高度
122 | /// DC源设备句柄
123 | /// 源对象的左上角X坐标
124 | /// 源对象的左上角Y坐标
125 | /// 光栅操作值
126 | ///
127 | [DllImport("gdi32.dll")]
128 | public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
129 | ///
130 | /// 使用当前选定的画笔和画刷进行矩形的绘制
131 | ///
132 | /// DC句柄
133 | /// 左上角x坐标
134 | /// 左上角y坐标
135 | /// 右下角x坐标
136 | /// 右下角y坐标
137 | ///
138 | [DllImport("gdi32.dll")]
139 | public static extern bool Rectangle(IntPtr hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
140 |
141 | #region Raster operation(BitBlt函数最后一个参数)
142 | ///
143 | /// 以黑色填充目标矩形区域。
144 | ///
145 | public static int RP_BLACKNESS = 0x42;
146 | ///
147 | /// 先将源矩形图像与目标矩形图像进行布尔“或”运算,然后再将图像进行反相。
148 | ///
149 | public static int RP_NOTSRCERASE = 0x001100A6;
150 | ///
151 | /// 将源矩形图像进行反相,复制到目标矩形上。
152 | ///
153 | public static int RP_NOTSRCCOPY = 0x330008;
154 | ///
155 | /// 将目标矩形图像进行反相.
156 | ///
157 | public static int RP_DSTINVERT = 0x550009;
158 | ///
159 | /// 将源矩形图像进行反相,与目标矩形图像进行布尔“或”运算。
160 | ///
161 | public static int RP_MERGEPAINT = 0x0BB0226;
162 | ///
163 | /// 将源矩形图像与指定的图案刷(Pattern)进行布尔“与”运算
164 | ///
165 | public static int RP_MERGECOPY = 0x00C000CA;
166 | ///
167 | /// 将源矩形图像与目标矩形图像进行布尔“与”运算。
168 | ///
169 | public static int RP_SRCAND = 0x008800C6;
170 | ///
171 | /// 将目标矩形图像直接复制到目标矩形。
172 | ///
173 | public static int RP_SRCCOPY = 0x00CC0020;
174 | ///
175 | /// 将目标矩形图像进行反相,再与源矩形图像进行布尔“与”运算。
176 | ///
177 | public static int RP_SRCERASE = 0x440328;
178 | ///
179 | /// 将源矩形图像与目标矩形图像进行布尔“或”运算。
180 | ///
181 | public static int RP_SRCPAINT = 0x00EE0086;
182 | ///
183 | /// 将源矩形图像与目标矩形图像进行布尔“异或”运算。
184 | ///
185 | public static int RP_SRCINVERT = 0x660046;
186 | ///
187 | /// 将指定的图案刷复制到目标矩形上。
188 | ///
189 | public static int RP_PATCOPY = 0x00F00021;
190 | ///
191 | /// 将指定的图案刷与目标矩形图像进行布尔“异或”运算。
192 | ///
193 | public static int RP_PATINVERT = 0x005A0049;
194 | ///
195 | /// 先将源矩形图像进行反相,与指定的图案刷进行布尔“或”运算,再与目标矩形图像进行布尔“或”运算
196 | ///
197 | public static int RP_PATPAINT = 0x00FB0A09;
198 | ///
199 | /// 用白色填充矩形区域。
200 | ///
201 | public static int RP_WHITENESS = 0x00FF0062;
202 | #endregion
203 |
204 | #endregion
205 | }
206 | }
--------------------------------------------------------------------------------
/GEDemo3/NativeStructure.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace GEDemo3
6 | {
7 | [StructLayout(LayoutKind.Sequential)]
8 | public class POINT
9 | {
10 | public int x;
11 | public int y;
12 |
13 | public POINT()
14 | {
15 | }
16 |
17 | public POINT(int x, int y)
18 | {
19 | this.x = x;
20 | this.y = y;
21 | }
22 | }
23 |
24 | [StructLayout(LayoutKind.Sequential)]
25 | public class POINTD
26 | {
27 | private double x;
28 | private double y;
29 | public double X
30 | {
31 | get { return this.x; }
32 | set { this.x = value; }
33 | }
34 | public double Y
35 | {
36 | get { return this.y; }
37 | set { this.y = value; }
38 | }
39 |
40 | public POINTD()
41 | {
42 | x = -1.0;
43 | y = -1.0;
44 | }
45 |
46 | public POINTD(double dx, double dy)
47 | {
48 | x = dx;
49 | y = dy;
50 | }
51 | }
52 |
53 | [StructLayout(LayoutKind.Sequential)]
54 | public struct RECT
55 | {
56 | public int left;
57 | public int top;
58 | public int width;
59 | public int height;
60 | }
61 |
62 | [StructLayout(LayoutKind.Sequential)]
63 | public struct SCROLLINFO
64 | {
65 | public uint cbSize;
66 | public uint fMask;
67 | public int nMin;
68 | public int nMax;
69 | public uint nPage;
70 | public int nPos;
71 | public int nTrackPos;
72 | }
73 |
74 | [StructLayout(LayoutKind.Sequential)]
75 | public struct MSG
76 | {
77 | public IntPtr hwnd;
78 |
79 | public uint message;
80 |
81 | public IntPtr WPARAM;
82 |
83 | public IntPtr LPARAM;
84 |
85 | public long Time;
86 |
87 | public POINT pt;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/GEDemo3/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | namespace GEDemo3
5 | {
6 | static class Program
7 | {
8 | ///
9 | /// 应用程序的主入口点。
10 | ///
11 | [STAThread]
12 | static void Main()
13 | {
14 | Application.EnableVisualStyles();
15 | Application.SetCompatibleTextRenderingDefault(false);
16 | Application.Run(new GEDemo3());
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/GEDemo3/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("GEDemo3")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("GEDemo3")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("f6660104-01d2-4459-a406-13894749e2cf")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/GEDemo3/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.18408
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace GEDemo3.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// 一个强类型的资源类,用于查找本地化的字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// 返回此类使用的缓存的 ResourceManager 实例。
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GEDemo3.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// 使用此强类型资源类,为所有资源查找
51 | /// 重写当前线程的 CurrentUICulture 属性。
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/GEDemo3/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/GEDemo3/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.18408
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace GEDemo3.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/GEDemo3/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/GEDemo3/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/GEDemo4/GEDemo4.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace GEDemo4
2 | {
3 | partial class GEDemo4
4 | {
5 | ///
6 | /// 必需的设计器变量。
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// 清理所有正在使用的资源。
12 | ///
13 | /// 如果应释放托管资源,为 true;否则为 false。
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows 窗体设计器生成的代码
24 |
25 | ///
26 | /// 设计器支持所需的方法 - 不要
27 | /// 使用代码编辑器修改此方法的内容。
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.components = new System.ComponentModel.Container();
32 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(GEDemo4));
33 | this.mainPanel = new System.Windows.Forms.Panel();
34 | this.tabDocker = new System.Windows.Forms.TabControl();
35 | this.tabGEViewer = new System.Windows.Forms.TabPage();
36 | this.tabXPViewer = new System.Windows.Forms.TabPage();
37 | this.toolBar = new System.Windows.Forms.ToolStrip();
38 | this.btnAppx = new System.Windows.Forms.ToolStripDropDownButton();
39 | this.btnStartGE = new System.Windows.Forms.ToolStripMenuItem();
40 | this.btnStopGE = new System.Windows.Forms.ToolStripMenuItem();
41 | this.btnExitApp = new System.Windows.Forms.ToolStripMenuItem();
42 | this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
43 | this.btnSnap = new System.Windows.Forms.ToolStripDropDownButton();
44 | this.btnGESnap = new System.Windows.Forms.ToolStripMenuItem();
45 | this.btnAPISnap = new System.Windows.Forms.ToolStripMenuItem();
46 | this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
47 | this.msgToolTip = new System.Windows.Forms.ToolTip(this.components);
48 | this.mainPanel.SuspendLayout();
49 | this.tabDocker.SuspendLayout();
50 | this.toolBar.SuspendLayout();
51 | this.SuspendLayout();
52 | //
53 | // mainPanel
54 | //
55 | this.mainPanel.Controls.Add(this.tabDocker);
56 | this.mainPanel.Controls.Add(this.toolBar);
57 | this.mainPanel.Dock = System.Windows.Forms.DockStyle.Fill;
58 | this.mainPanel.Location = new System.Drawing.Point(0, 0);
59 | this.mainPanel.Name = "mainPanel";
60 | this.mainPanel.Size = new System.Drawing.Size(1182, 855);
61 | this.mainPanel.TabIndex = 0;
62 | //
63 | // tabDocker
64 | //
65 | this.tabDocker.Controls.Add(this.tabGEViewer);
66 | this.tabDocker.Controls.Add(this.tabXPViewer);
67 | this.tabDocker.Dock = System.Windows.Forms.DockStyle.Fill;
68 | this.tabDocker.Location = new System.Drawing.Point(0, 30);
69 | this.tabDocker.Name = "tabDocker";
70 | this.tabDocker.SelectedIndex = 0;
71 | this.tabDocker.Size = new System.Drawing.Size(1182, 825);
72 | this.tabDocker.TabIndex = 1;
73 | //
74 | // tabGEViewer
75 | //
76 | this.tabGEViewer.BackColor = System.Drawing.Color.LightGray;
77 | this.tabGEViewer.Location = new System.Drawing.Point(4, 32);
78 | this.tabGEViewer.Name = "tabGEViewer";
79 | this.tabGEViewer.Padding = new System.Windows.Forms.Padding(3);
80 | this.tabGEViewer.Size = new System.Drawing.Size(1174, 789);
81 | this.tabGEViewer.TabIndex = 0;
82 | this.tabGEViewer.Text = "GEViewer";
83 | //
84 | // tabXPViewer
85 | //
86 | this.tabXPViewer.BackColor = System.Drawing.Color.LightGray;
87 | this.tabXPViewer.Location = new System.Drawing.Point(4, 32);
88 | this.tabXPViewer.Name = "tabXPViewer";
89 | this.tabXPViewer.Padding = new System.Windows.Forms.Padding(3);
90 | this.tabXPViewer.Size = new System.Drawing.Size(1174, 789);
91 | this.tabXPViewer.TabIndex = 1;
92 | this.tabXPViewer.Text = "XPViewer";
93 | //
94 | // toolBar
95 | //
96 | this.toolBar.Font = new System.Drawing.Font("Cambria", 12F);
97 | this.toolBar.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
98 | this.btnAppx,
99 | this.toolStripSeparator1,
100 | this.btnSnap,
101 | this.toolStripSeparator2});
102 | this.toolBar.Location = new System.Drawing.Point(0, 0);
103 | this.toolBar.Name = "toolBar";
104 | this.toolBar.Size = new System.Drawing.Size(1182, 30);
105 | this.toolBar.TabIndex = 0;
106 | this.toolBar.Text = "toolStrip1";
107 | //
108 | // btnAppx
109 | //
110 | this.btnAppx.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
111 | this.btnStartGE,
112 | this.btnStopGE,
113 | this.btnExitApp});
114 | this.btnAppx.Image = ((System.Drawing.Image)(resources.GetObject("btnAppx.Image")));
115 | this.btnAppx.ImageTransparentColor = System.Drawing.Color.Magenta;
116 | this.btnAppx.Name = "btnAppx";
117 | this.btnAppx.Size = new System.Drawing.Size(79, 27);
118 | this.btnAppx.Text = "开始";
119 | //
120 | // btnStartGE
121 | //
122 | this.btnStartGE.Name = "btnStartGE";
123 | this.btnStartGE.Size = new System.Drawing.Size(164, 28);
124 | this.btnStartGE.Text = "启动GE";
125 | this.btnStartGE.Click += new System.EventHandler(this.btnStartGE_Click);
126 | //
127 | // btnStopGE
128 | //
129 | this.btnStopGE.Name = "btnStopGE";
130 | this.btnStopGE.Size = new System.Drawing.Size(164, 28);
131 | this.btnStopGE.Text = "关闭GE";
132 | this.btnStopGE.Click += new System.EventHandler(this.btnStopGE_Click);
133 | //
134 | // btnExitApp
135 | //
136 | this.btnExitApp.Name = "btnExitApp";
137 | this.btnExitApp.Size = new System.Drawing.Size(164, 28);
138 | this.btnExitApp.Text = "退出程序";
139 | //
140 | // toolStripSeparator1
141 | //
142 | this.toolStripSeparator1.Name = "toolStripSeparator1";
143 | this.toolStripSeparator1.Size = new System.Drawing.Size(6, 30);
144 | //
145 | // btnSnap
146 | //
147 | this.btnSnap.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
148 | this.btnGESnap,
149 | this.btnAPISnap});
150 | this.btnSnap.Image = ((System.Drawing.Image)(resources.GetObject("btnSnap.Image")));
151 | this.btnSnap.ImageTransparentColor = System.Drawing.Color.Magenta;
152 | this.btnSnap.Name = "btnSnap";
153 | this.btnSnap.Size = new System.Drawing.Size(79, 27);
154 | this.btnSnap.Text = "截图";
155 | //
156 | // btnGESnap
157 | //
158 | this.btnGESnap.Name = "btnGESnap";
159 | this.btnGESnap.Size = new System.Drawing.Size(153, 28);
160 | this.btnGESnap.Text = "GE截图";
161 | this.btnGESnap.Click += new System.EventHandler(this.btnGESnap_Click);
162 | //
163 | // btnAPISnap
164 | //
165 | this.btnAPISnap.Name = "btnAPISnap";
166 | this.btnAPISnap.Size = new System.Drawing.Size(153, 28);
167 | this.btnAPISnap.Text = "API截图";
168 | this.btnAPISnap.Click += new System.EventHandler(this.btnAPISnap_Click);
169 | //
170 | // toolStripSeparator2
171 | //
172 | this.toolStripSeparator2.Name = "toolStripSeparator2";
173 | this.toolStripSeparator2.Size = new System.Drawing.Size(6, 30);
174 | //
175 | // GEDemo4
176 | //
177 | this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 23F);
178 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
179 | this.ClientSize = new System.Drawing.Size(1182, 855);
180 | this.Controls.Add(this.mainPanel);
181 | this.Font = new System.Drawing.Font("Cambria", 12F);
182 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
183 | this.Margin = new System.Windows.Forms.Padding(4);
184 | this.Name = "GEDemo4";
185 | this.Text = "GEDemo4";
186 | this.mainPanel.ResumeLayout(false);
187 | this.mainPanel.PerformLayout();
188 | this.tabDocker.ResumeLayout(false);
189 | this.toolBar.ResumeLayout(false);
190 | this.toolBar.PerformLayout();
191 | this.ResumeLayout(false);
192 |
193 | }
194 |
195 | #endregion
196 |
197 | private System.Windows.Forms.Panel mainPanel;
198 | private System.Windows.Forms.ToolStrip toolBar;
199 | private System.Windows.Forms.ToolStripDropDownButton btnAppx;
200 | private System.Windows.Forms.ToolStripMenuItem btnStartGE;
201 | private System.Windows.Forms.ToolStripMenuItem btnStopGE;
202 | private System.Windows.Forms.ToolStripMenuItem btnExitApp;
203 | private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
204 | private System.Windows.Forms.ToolStripDropDownButton btnSnap;
205 | private System.Windows.Forms.ToolStripMenuItem btnGESnap;
206 | private System.Windows.Forms.ToolStripMenuItem btnAPISnap;
207 | private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
208 | private System.Windows.Forms.TabControl tabDocker;
209 | private System.Windows.Forms.TabPage tabGEViewer;
210 | private System.Windows.Forms.TabPage tabXPViewer;
211 | private System.Windows.Forms.ToolTip msgToolTip;
212 | }
213 | }
214 |
215 |
--------------------------------------------------------------------------------
/GEDemo4/GEDemo4.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 | using System.ComponentModel;
4 | using EARTHLib;
5 | using System.Drawing;
6 | using System.Drawing.Imaging;
7 | using System.Diagnostics;
8 | using System.Drawing.Drawing2D;
9 |
10 |
11 | namespace GEDemo4
12 | {
13 | public partial class GEDemo4 : Form
14 | {
15 | private IntPtr GEHMainWnd = (IntPtr)0;
16 | private IntPtr GEHRenderWnd = (IntPtr)0;
17 |
18 | private ApplicationGE GEApp = null;
19 | private bool isGEStarted = false;
20 |
21 | public GEDemo4()
22 | {
23 | InitializeComponent();
24 | SetBackgroundImage(tabGEViewer);
25 | }
26 |
27 | protected override void OnClosing(CancelEventArgs e)
28 | {
29 | base.OnClosing(e);
30 | if (isGEStarted)
31 | {
32 | TryCloseGE();
33 | }
34 | }
35 |
36 | protected override void OnSizeChanged(EventArgs e)
37 | {
38 | base.OnSizeChanged(e);
39 |
40 | if (isGEStarted)
41 | {
42 | ResizeTabPage(tabGEViewer);
43 | }
44 | }
45 |
46 | #region GEFunctions
47 |
48 | ///
49 | /// 功能:尝试启动Google Earth实例
50 | ///
51 | ///
52 | /// 参数:parentDocker
53 | /// 含义:GE渲染窗口所停靠的父窗口
54 | ///
55 | private void TryStartGE(Control parentDocker)
56 | {
57 | try
58 | {
59 | //创建GE新实例
60 | GEApp = new ApplicationGE();
61 | //取得GE主窗口句柄
62 | GEHMainWnd = (IntPtr)GEApp.GetMainHwnd();
63 | //隐藏GoogleEarth主窗口
64 | NativeMethods.SetWindowPos(GEHMainWnd, NativeMethods.HWND_BOTTOM,
65 | 0, 0, 0, 0, NativeMethods.SWP_NOSIZE | NativeMethods.SWP_HIDEWINDOW);
66 | //取得GE的影像窗口(渲染窗口)句柄
67 | GEHRenderWnd = (IntPtr)GEApp.GetRenderHwnd();
68 | //调整视图窗口尺寸
69 | ResizeTabPage(tabGEViewer);
70 | //启动成功,设置标记
71 | isGEStarted = true;
72 | }
73 | catch (Exception ex)
74 | {
75 | MessageBox.Show(ex.Message, "Error Starting GE");
76 | }
77 | }
78 |
79 | ///
80 | /// 功能:尝试关闭GE
81 | ///
82 | private void TryCloseGE()
83 | {
84 | try
85 | {
86 | //杀掉GoogleEarth进程
87 | Process[] geProcess = Process.GetProcessesByName("GoogleEarth");
88 | foreach (var p in geProcess)
89 | {
90 | p.Kill();
91 | }
92 | //清除内容
93 | GEApp = null;
94 | GEHMainWnd = (IntPtr)0;
95 | GEHRenderWnd = (IntPtr)0;
96 | isGEStarted = false;
97 | }
98 | catch (Exception ex)
99 | {
100 | MessageBox.Show(ex.Message, "Error Shutdown GE");
101 | }
102 | }
103 |
104 | ///
105 | /// 功能:重设GE渲染窗口的尺寸
106 | ///
107 | /// 参数:parentDocker
108 | /// 含义:GE渲染窗口所停靠的父窗口
109 | ///
110 | private void ResizeTabPage(TabPage parentDocker)
111 | {
112 | RECT rect = new RECT();
113 | NativeMethods.GetClientRect(GEHRenderWnd, out rect);
114 |
115 | int left = (parentDocker.Width - rect.Width) / 2;
116 | int top = (parentDocker.Height - rect.Height) / 2;
117 | if (left < 0) left = 0;
118 | if (top < 0) top = 0;
119 | parentDocker.AutoScrollMinSize = new Size(rect.Width, rect.Height);
120 | //将渲染窗口嵌入到父窗体合适位置
121 | NativeMethods.MoveWindow(GEHRenderWnd, left, top, rect.Width, rect.Height, true);
122 | NativeMethods.SetParent(GEHRenderWnd, parentDocker.Handle);
123 | }
124 |
125 | #endregion GEFunctions
126 |
127 | #region MessageHandlers
128 |
129 | private void btnStartGE_Click(object sender, EventArgs e)
130 | {
131 | if (CheckGEState(false, "Startup Google Earth"))
132 | {
133 | SetBackgroundImage(tabGEViewer, true);
134 | TryStartGE(tabGEViewer);
135 | ResizeTabPage(tabGEViewer);
136 | }
137 | }
138 |
139 | private void btnStopGE_Click(object sender, EventArgs e)
140 | {
141 | if (CheckGEState(true, "Shutdown Google Earth"))
142 | {
143 | SetBackgroundImage(tabGEViewer);
144 | TryCloseGE();
145 | }
146 | }
147 |
148 | private void btnGESnap_Click(object sender, EventArgs e)
149 | {
150 | if (CheckGEState(true, "GESnap"))
151 | {
152 | using (SaveFileDialog sfd = new SaveFileDialog())
153 | {
154 | sfd.Filter = "JPEG图片(*.jpg)|*.jpg";
155 | sfd.AddExtension = true;
156 | sfd.CheckPathExists = true;
157 | sfd.Title = "保存Google Earth截图";
158 |
159 | if (sfd.ShowDialog() == DialogResult.OK)
160 | {
161 | GEApp.SaveScreenShot(sfd.FileName, 100);
162 | msgToolTip.Show("\'" + sfd.FileName + "\' Saved", tabGEViewer, tabGEViewer.Width / 4, tabGEViewer.Height / 4, 2000);
163 | }
164 | }
165 | }
166 | }
167 |
168 | private void btnAPISnap_Click(object sender, EventArgs e)
169 | {
170 | if (CheckGEState(true, "APISnap"))
171 | {
172 | RECT rect = new RECT();
173 | NativeMethods.GetClientRect(GEHRenderWnd, out rect);
174 |
175 | // 取得Render DC
176 | IntPtr hRenderDC = NativeMethods.GetWindowDC(GEHRenderWnd);
177 | // 创建hBitmap
178 | IntPtr hBitmap = NativeMethods.CreateCompatibleBitmap(hRenderDC, rect.Width, rect.Height);
179 | // 创建MEM DC
180 | IntPtr hMemDC = NativeMethods.CreateCompatibleDC(hRenderDC);
181 | // 将Bitmap Select到MemDC
182 | NativeMethods.SelectObject(hMemDC, hBitmap);
183 | // 直接拷屏
184 | NativeMethods.BitBlt(hMemDC, rect.left, rect.top, rect.Width, rect.Height, hRenderDC, 0, 0, NativeMethods.SRCCOPY);
185 |
186 | #region SaveImage
187 |
188 | using (Bitmap bmp = Bitmap.FromHbitmap(hBitmap))
189 | {
190 | using (SaveFileDialog sfd = new SaveFileDialog())
191 | {
192 | sfd.Filter = "JPEG图片(*.jpg)|*.jpg|PNG图片(*.png)|*.png";
193 | sfd.AddExtension = true;
194 | sfd.CheckPathExists = true;
195 | sfd.Title = "保存Google Earth截图";
196 |
197 | if (sfd.ShowDialog() == DialogResult.OK)
198 | {
199 | ImageFormat imgFormat = null;
200 | // 默认选择JPG
201 | if (sfd.FilterIndex == 0)
202 | {
203 | imgFormat = ImageFormat.Jpeg;
204 | }
205 | // 选择PNG
206 | else
207 | {
208 | imgFormat = ImageFormat.Png;
209 | }
210 | bmp.Save(sfd.FileName, imgFormat);
211 | msgToolTip.Show("\'" + sfd.FileName + "\' Saved", tabGEViewer, tabGEViewer.Width / 4, tabGEViewer.Height / 4, 2000);
212 | }
213 | }
214 | //销毁资源
215 | NativeMethods.DeleteDC(hRenderDC);
216 | NativeMethods.DeleteDC(hMemDC);
217 | }
218 |
219 | #endregion SaveImage
220 | }
221 |
222 | }
223 |
224 | #endregion MessageHandlers
225 |
226 | private bool CheckGEState(bool bExpRun, string caption)
227 | {
228 | bool state = true;
229 | if (bExpRun)
230 | {
231 | //期望GE运行而实际并未运行
232 | if (!isGEStarted)
233 | {
234 | MessageBox.Show("Goolge Earth is not running", caption);
235 | state = false;
236 | }
237 | }
238 | else
239 | {
240 | //期望GE关闭而实际正在运行
241 | if (isGEStarted)
242 | {
243 | MessageBox.Show("Goolge Earth is running currently", caption);
244 | state = false;
245 | }
246 | }
247 |
248 | return state;
249 | }
250 |
251 | //reset=true表示清除背景图片
252 | private void SetBackgroundImage(Control control, bool reset=false)
253 | {
254 | if (reset)
255 | {
256 | control.BackgroundImage = null;
257 | }
258 | else
259 | {
260 | control.BackgroundImage = Properties.Resources.GEBgnd;
261 | control.BackgroundImageLayout = ImageLayout.Stretch;
262 | }
263 | }
264 | }
265 | }
266 |
--------------------------------------------------------------------------------
/GEDemo4/GEDemo4.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {52356277-5AF4-4978-8AAA-015EE94BD17C}
8 | WinExe
9 | Properties
10 | GEDemo4
11 | GEDemo4
12 | v2.0
13 | 512
14 |
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | x86
28 | pdbonly
29 | true
30 | ..\bin\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 | Resources\GEApp.ico
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | Form
49 |
50 |
51 | GEDemo4.cs
52 |
53 |
54 |
55 |
56 |
57 |
58 | GEDemo4.cs
59 |
60 |
61 | ResXFileCodeGenerator
62 | Designer
63 | Resources.Designer.cs
64 |
65 |
66 |
67 | SettingsSingleFileGenerator
68 | Settings.Designer.cs
69 |
70 |
71 | True
72 | True
73 | Resources.resx
74 |
75 |
76 | True
77 | Settings.settings
78 | True
79 |
80 |
81 |
82 |
83 | {3476FAB2-687F-4EA6-9AC2-88D72DC7D7FC}
84 | 1
85 | 0
86 | 0
87 | tlbimp
88 | False
89 | True
90 |
91 |
92 | {00020430-0000-0000-C000-000000000046}
93 | 2
94 | 0
95 | 0
96 | primary
97 | False
98 | True
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
121 |
--------------------------------------------------------------------------------
/GEDemo4/NativeMethods.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 | using System.Runtime.InteropServices;
4 | using System.Drawing;
5 |
6 | namespace GEDemo4
7 | {
8 | public class NativeMethods
9 | {
10 | [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
11 | public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, UInt32 uflags);
12 |
13 | [DllImport("user32.dll", CharSet = CharSet.Auto)]
14 | public static extern IntPtr PostMessage(IntPtr hWnd, int msg, int wParam, int lParam);
15 | [DllImport("user32.dll")]
16 | public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
17 | [DllImport("user32.dll", CharSet = CharSet.Auto)]
18 | public static extern int GetMessage(out MSG msg, IntPtr hWnd, int wMsgFilterMin, int wMsgFilterMax);
19 | [DllImport("user32.dll", CharSet = CharSet.Auto)]
20 | public static extern int PeekMessage(out MSG msg, IntPtr hWnd, int wMsgFilterMin, int wMsgFilterMax);
21 | [DllImport("user32.dll", CharSet = CharSet.Auto)]
22 | public static extern long DispatchMessage(MSG msg);
23 |
24 | [DllImport("user32.dll")]
25 | public static extern IntPtr FindWindow(string className, string windowTitle);
26 | [DllImport("user32.dll")]
27 | public static extern bool ShowWindowAsync(int hWnd, int nCmdShow);
28 |
29 | [DllImport("user32.dll")]
30 | public static extern bool GetWindowRect(IntPtr hWnd, out RECT rect);
31 |
32 | [DllImport("user32.dll")]
33 | public static extern bool GetClientRect(IntPtr hWnd, out RECT rect);
34 |
35 | [DllImport("user32.dll")]
36 | public static extern IntPtr GetDesktopWindow();
37 |
38 | [DllImport("user32")]
39 | public static extern IntPtr GetWindowDC(IntPtr hwnd);
40 |
41 | [DllImport("user32")]
42 | public static extern IntPtr GetDC(IntPtr hwnd);
43 |
44 | [DllImport("user32")]
45 | public static extern long ReleaseDC(IntPtr handle, IntPtr hdc);
46 |
47 | [DllImport("user32")]
48 | public static extern IntPtr WindowFromPoint(Point point);
49 |
50 | [DllImport("user32")]
51 | public static extern bool PrintWindow(IntPtr hWnd, IntPtr hdcBlt, UInt32 nFlags);
52 |
53 | [DllImport("kernel32.dll", SetLastError = true)]
54 | [return: MarshalAs(UnmanagedType.Bool)]
55 | public static extern bool CloseHandle(IntPtr hObject);
56 |
57 | #region 预定义
58 |
59 | public static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
60 | public static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
61 | public static readonly IntPtr HWND_TOP = new IntPtr(0);
62 | public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
63 | public static readonly uint SWP_NOSIZE = 1U;
64 | public static readonly uint SWP_NOMOVE = 2U;
65 | public static readonly uint SWP_NOZORDER = 4U;
66 | public static readonly uint SWP_NOREDRAW = 8U;
67 | public static readonly uint SWP_NOACTIVATE = 16U;
68 | public static readonly uint SWP_FRAMECHANGED = 32U;
69 | public static readonly uint SWP_SHOWWINDOW = 64U;
70 | public static readonly uint SWP_HIDEWINDOW = 128U;
71 | public static readonly uint SWP_NOCOPYBITS = 256U;
72 | public static readonly uint SWP_NOOWNERZORDER = 512U;
73 | public static readonly uint SWP_NOSENDCHANGING = 1024U;
74 | public static readonly int WM_COMMAND = 0x0112;
75 | public static readonly int WM_QT_PAINT = 0xC2DC;
76 | public static readonly int WM_PAINT = 0x000F;
77 | public static readonly int WM_SIZE = 0x0005;
78 | public static readonly int SRCCOPY = 0xCC0020;
79 |
80 | #endregion
81 |
82 | public delegate int EnumWindowsProc(IntPtr hWnd, int lParam);
83 |
84 | [DllImport("user32", CharSet = CharSet.Auto)]
85 | public extern static IntPtr GetParent(IntPtr hWnd);
86 |
87 | [DllImport("user32", CharSet = CharSet.Auto)]
88 | public extern static bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
89 |
90 | [DllImport("user32", CharSet = CharSet.Auto)]
91 | public extern static IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
92 |
93 | [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
94 | public static extern IntPtr GetWindow(IntPtr hWnd, int uCmd);
95 |
96 | public static int GW_CHILD = 5;
97 | public static int GW_HWNDNEXT = 2;
98 |
99 | #region GDI绘图函数
100 |
101 | [DllImport("gdi32.dll")]
102 | public static extern IntPtr CreateCompatibleDC(IntPtr hwnd);
103 |
104 | [DllImport("gdi32.dll")]
105 | public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidht, int nHeight);
106 |
107 | [DllImport("gdi32.dll")]
108 | public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
109 |
110 | [DllImport("gdi32.dll")]
111 | public static extern int DeleteDC(IntPtr hdc);
112 |
113 | [DllImport("gdi32.dll")]
114 | public static extern IntPtr CreateDC(string lpszDriver, string lpszDevice, string lpszOutput, IntPtr lpInitData);
115 | ///
116 | /// API函数BitBlt
117 | ///
118 | /// DC目标设备句柄
119 | /// 目标对象的左上角X坐标
120 | /// 目标对象的左上角Y坐标
121 | /// 目标对象的矩形宽度
122 | /// 目标对象的矩形高度
123 | /// DC源设备句柄
124 | /// 源对象的左上角X坐标
125 | /// 源对象的左上角Y坐标
126 | /// 光栅操作值
127 | ///
128 | [DllImport("gdi32.dll")]
129 | public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
130 | ///
131 | /// 使用当前选定的画笔和画刷进行矩形的绘制
132 | ///
133 | /// DC句柄
134 | /// 左上角x坐标
135 | /// 左上角y坐标
136 | /// 右下角x坐标
137 | /// 右下角y坐标
138 | ///
139 | [DllImport("gdi32.dll")]
140 | public static extern bool Rectangle(IntPtr hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
141 |
142 | #region Raster operation(BitBlt函数最后一个参数)
143 | ///
144 | /// 以黑色填充目标矩形区域。
145 | ///
146 | public static int RP_BLACKNESS = 0x42;
147 | ///
148 | /// 先将源矩形图像与目标矩形图像进行布尔“或”运算,然后再将图像进行反相。
149 | ///
150 | public static int RP_NOTSRCERASE = 0x001100A6;
151 | ///
152 | /// 将源矩形图像进行反相,复制到目标矩形上。
153 | ///
154 | public static int RP_NOTSRCCOPY = 0x330008;
155 | ///
156 | /// 将目标矩形图像进行反相.
157 | ///
158 | public static int RP_DSTINVERT = 0x550009;
159 | ///
160 | /// 将源矩形图像进行反相,与目标矩形图像进行布尔“或”运算。
161 | ///
162 | public static int RP_MERGEPAINT = 0x0BB0226;
163 | ///
164 | /// 将源矩形图像与指定的图案刷(Pattern)进行布尔“与”运算
165 | ///
166 | public static int RP_MERGECOPY = 0x00C000CA;
167 | ///
168 | /// 将源矩形图像与目标矩形图像进行布尔“与”运算。
169 | ///
170 | public static int RP_SRCAND = 0x008800C6;
171 | ///
172 | /// 将目标矩形图像直接复制到目标矩形。
173 | ///
174 | public static int RP_SRCCOPY = 0x00CC0020;
175 | ///
176 | /// 将目标矩形图像进行反相,再与源矩形图像进行布尔“与”运算。
177 | ///
178 | public static int RP_SRCERASE = 0x440328;
179 | ///
180 | /// 将源矩形图像与目标矩形图像进行布尔“或”运算。
181 | ///
182 | public static int RP_SRCPAINT = 0x00EE0086;
183 | ///
184 | /// 将源矩形图像与目标矩形图像进行布尔“异或”运算。
185 | ///
186 | public static int RP_SRCINVERT = 0x660046;
187 | ///
188 | /// 将指定的图案刷复制到目标矩形上。
189 | ///
190 | public static int RP_PATCOPY = 0x00F00021;
191 | ///
192 | /// 将指定的图案刷与目标矩形图像进行布尔“异或”运算。
193 | ///
194 | public static int RP_PATINVERT = 0x005A0049;
195 | ///
196 | /// 先将源矩形图像进行反相,与指定的图案刷进行布尔“或”运算,再与目标矩形图像进行布尔“或”运算
197 | ///
198 | public static int RP_PATPAINT = 0x00FB0A09;
199 | ///
200 | /// 用白色填充矩形区域。
201 | ///
202 | public static int RP_WHITENESS = 0x00FF0062;
203 | #endregion
204 |
205 | #endregion
206 | }
207 | }
--------------------------------------------------------------------------------
/GEDemo4/NativeStructure.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace GEDemo4
6 | {
7 | [StructLayout(LayoutKind.Sequential)]
8 | public class POINT
9 | {
10 | public int x;
11 | public int y;
12 |
13 | public POINT()
14 | {
15 | }
16 |
17 | public POINT(int x, int y)
18 | {
19 | this.x = x;
20 | this.y = y;
21 | }
22 | }
23 |
24 | [StructLayout(LayoutKind.Sequential)]
25 | public class POINTD
26 | {
27 | private double x;
28 | private double y;
29 | public double X
30 | {
31 | get { return this.x; }
32 | set { this.x = value; }
33 | }
34 | public double Y
35 | {
36 | get { return this.y; }
37 | set { this.y = value; }
38 | }
39 |
40 | public POINTD()
41 | {
42 | x = -1.0;
43 | y = -1.0;
44 | }
45 |
46 | public POINTD(double dx, double dy)
47 | {
48 | x = dx;
49 | y = dy;
50 | }
51 | }
52 |
53 | [StructLayout(LayoutKind.Sequential)]
54 | public struct RECT
55 | {
56 | public int left;
57 | public int top;
58 | public int Width;
59 | public int Height;
60 | }
61 |
62 | [StructLayout(LayoutKind.Sequential)]
63 | public struct SCROLLINFO
64 | {
65 | public uint cbSize;
66 | public uint fMask;
67 | public int nMin;
68 | public int nMax;
69 | public uint nPage;
70 | public int nPos;
71 | public int nTrackPos;
72 | }
73 |
74 | [StructLayout(LayoutKind.Sequential)]
75 | public struct MSG
76 | {
77 | public IntPtr hwnd;
78 |
79 | public uint message;
80 |
81 | public IntPtr WPARAM;
82 |
83 | public IntPtr LPARAM;
84 |
85 | public long Time;
86 |
87 | public POINT pt;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/GEDemo4/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | namespace GEDemo4
5 | {
6 | static class Program
7 | {
8 | ///
9 | /// 应用程序的主入口点。
10 | ///
11 | [STAThread]
12 | static void Main()
13 | {
14 | Application.EnableVisualStyles();
15 | Application.SetCompatibleTextRenderingDefault(false);
16 | Application.Run(new GEDemo4());
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/GEDemo4/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("GEDemo4")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("GEDemo4")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("7da38045-20bf-4375-aab3-d1b7a02e3570")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/GEDemo4/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.18408
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace GEDemo4.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// 一个强类型的资源类,用于查找本地化的字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// 返回此类使用的缓存的 ResourceManager 实例。
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GEDemo4.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// 使用此强类型资源类,为所有资源查找
51 | /// 重写当前线程的 CurrentUICulture 属性。
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// 查找类似于 (Icon) 的 System.Drawing.Icon 类型的本地化资源。
65 | ///
66 | internal static System.Drawing.Icon GEApp {
67 | get {
68 | object obj = ResourceManager.GetObject("GEApp", resourceCulture);
69 | return ((System.Drawing.Icon)(obj));
70 | }
71 | }
72 |
73 | ///
74 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。
75 | ///
76 | internal static System.Drawing.Bitmap GEBgnd {
77 | get {
78 | object obj = ResourceManager.GetObject("GEBgnd", resourceCulture);
79 | return ((System.Drawing.Bitmap)(obj));
80 | }
81 | }
82 |
83 | ///
84 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。
85 | ///
86 | internal static System.Drawing.Bitmap GESnap {
87 | get {
88 | object obj = ResourceManager.GetObject("GESnap", resourceCulture);
89 | return ((System.Drawing.Bitmap)(obj));
90 | }
91 | }
92 |
93 | ///
94 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。
95 | ///
96 | internal static System.Drawing.Bitmap GEStart {
97 | get {
98 | object obj = ResourceManager.GetObject("GEStart", resourceCulture);
99 | return ((System.Drawing.Bitmap)(obj));
100 | }
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/GEDemo4/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 |
122 | ..\Resources\GEApp.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
123 |
124 |
125 | ..\Resources\GEBgnd.jpg;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
126 |
127 |
128 | ..\Resources\GESnap.jpg;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
129 |
130 |
131 | ..\Resources\GEStart.jpg;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
132 |
133 |
--------------------------------------------------------------------------------
/GEDemo4/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18408
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace GEDemo4.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/GEDemo4/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/GEDemo4/Resources/GEApp.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengyhack/LearningGoogleEarthNET/4a3c04ecc754385e56e5b1cb24e37aed835de6b9/GEDemo4/Resources/GEApp.ico
--------------------------------------------------------------------------------
/GEDemo4/Resources/GEBgnd.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengyhack/LearningGoogleEarthNET/4a3c04ecc754385e56e5b1cb24e37aed835de6b9/GEDemo4/Resources/GEBgnd.jpg
--------------------------------------------------------------------------------
/GEDemo4/Resources/GESnap.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengyhack/LearningGoogleEarthNET/4a3c04ecc754385e56e5b1cb24e37aed835de6b9/GEDemo4/Resources/GESnap.jpg
--------------------------------------------------------------------------------
/GEDemo4/Resources/GEStart.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengyhack/LearningGoogleEarthNET/4a3c04ecc754385e56e5b1cb24e37aed835de6b9/GEDemo4/Resources/GEStart.jpg
--------------------------------------------------------------------------------
/GEDemo4/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/GEDemo5/GEDemo5.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 | using System.ComponentModel;
4 | using EARTHLib;
5 | using System.Drawing;
6 | using System.Drawing.Imaging;
7 | using System.Diagnostics;
8 |
9 |
10 | namespace GEDemo5
11 | {
12 | public struct SCamParams
13 | {
14 | public double dLat;
15 | public double dLon;
16 | public double dAlt;
17 | public double dRng;
18 | public double dAng;
19 | public double dAzm;
20 | public double dSpd;
21 | }
22 | public partial class GEDemo5 : Form
23 | {
24 | #region PrivateMembers
25 |
26 | private IntPtr GEHMainWnd = (IntPtr)0;
27 | private IntPtr GEHRenderWnd = (IntPtr)0;
28 |
29 | private ApplicationGE GEApp = null;
30 | private bool isGEStarted = false;
31 |
32 | SCamParams scp = new SCamParams();
33 |
34 | #endregion PrivateMembers
35 |
36 | public GEDemo5()
37 | {
38 | InitializeComponent();
39 | WindowState = FormWindowState.Maximized; //最大化显示
40 | tabDocker.TabPages.Clear();
41 | tabDocker.TabPages.Add(tabGEViewer);
42 | SetBackgroundImage(tabGEViewer);
43 | SetParamsDefault();
44 | }
45 |
46 | #region GEFunctions
47 |
48 | ///
49 | /// 功能:尝试启动Google Earth实例
50 | ///
51 | ///
52 | /// 参数:parentDocker
53 | /// 含义:GE渲染窗口所停靠的父窗口
54 | ///
55 | private void TryStartGE(Control parentDocker)
56 | {
57 | try
58 | {
59 | //创建GE新实例
60 | GEApp = new ApplicationGE();
61 | //取得GE主窗口句柄
62 | GEHMainWnd = (IntPtr)GEApp.GetMainHwnd();
63 | //隐藏GoogleEarth主窗口
64 | NativeMethods.SetWindowPos(GEHMainWnd, NativeMethods.HWND_BOTTOM,
65 | 0, 0, 0, 0, NativeMethods.SWP_NOSIZE | NativeMethods.SWP_HIDEWINDOW);
66 | //取得GE的影像窗口(渲染窗口)句柄
67 | GEHRenderWnd = (IntPtr)GEApp.GetRenderHwnd();
68 | //调整视图窗口尺寸
69 | ResizeTabPage(tabGEViewer);
70 | //启动成功,设置标记
71 | isGEStarted = true;
72 | }
73 | catch (Exception ex)
74 | {
75 | MessageBox.Show(ex.Message, "Error Starting GE");
76 | }
77 | }
78 |
79 | ///
80 | /// 功能:尝试关闭GE
81 | ///
82 | private void TryCloseGE()
83 | {
84 | try
85 | {
86 | //杀掉GoogleEarth进程
87 | Process[] geProcess = Process.GetProcessesByName("GoogleEarth");
88 | foreach (var p in geProcess)
89 | {
90 | p.Kill();
91 | }
92 | //清除内容
93 | GEApp = null;
94 | GEHMainWnd = (IntPtr)0;
95 | GEHRenderWnd = (IntPtr)0;
96 | isGEStarted = false;
97 | }
98 | catch (Exception ex)
99 | {
100 | MessageBox.Show(ex.Message, "Error Shutdown GE");
101 | }
102 | }
103 |
104 | ///
105 | /// 功能:重设GE渲染窗口的尺寸
106 | ///
107 | /// 参数:parentDocker
108 | /// 含义:GE渲染窗口所停靠的父窗口
109 | ///
110 | private void ResizeTabPage(TabPage parentDocker)
111 | {
112 | RECT rect = new RECT();
113 | NativeMethods.GetClientRect(GEHRenderWnd, out rect);
114 |
115 | int left = (parentDocker.Width - rect.Width) / 2;
116 | int top = (parentDocker.Height - rect.Height) / 2;
117 | if (left < 0) left = 0;
118 | if (top < 0) top = 0;
119 | parentDocker.AutoScrollMinSize = new Size(rect.Width, rect.Height);
120 | //将渲染窗口嵌入到父窗体合适位置
121 | NativeMethods.MoveWindow(GEHRenderWnd, left, top, rect.Width, rect.Height, true);
122 | NativeMethods.SetParent(GEHRenderWnd, parentDocker.Handle);
123 | }
124 |
125 | #endregion GEFunctions
126 |
127 | #region MessageHandlers
128 |
129 | protected override void OnClosing(CancelEventArgs e)
130 | {
131 | base.OnClosing(e);
132 | if (isGEStarted)
133 | {
134 | TryCloseGE();
135 | }
136 | }
137 |
138 | protected override void OnSizeChanged(EventArgs e)
139 | {
140 | base.OnSizeChanged(e);
141 |
142 | if (isGEStarted)
143 | {
144 | ResizeTabPage(tabGEViewer);
145 | }
146 | }
147 |
148 | private void btnStartGE_Click(object sender, EventArgs e)
149 | {
150 | if (CheckGEState(false, "Startup Google Earth"))
151 | {
152 | SetBackgroundImage(tabGEViewer, true);
153 | TryStartGE(tabGEViewer);
154 | ResizeTabPage(tabGEViewer);
155 | }
156 | }
157 |
158 | private void btnStopGE_Click(object sender, EventArgs e)
159 | {
160 | if (CheckGEState(true, "Shutdown Google Earth"))
161 | {
162 | SetBackgroundImage(tabGEViewer);
163 | TryCloseGE();
164 | }
165 | }
166 |
167 | private void btnExitApp_Click(object sender, EventArgs e)
168 | {
169 | if (DialogResult.OK != MessageBox.Show("Are you sure to exit?", "Exit Confirm", MessageBoxButtons.OKCancel))
170 | {
171 | return;
172 | }
173 | if (isGEStarted)
174 | {
175 | TryCloseGE();
176 | }
177 | Application.Exit();
178 | }
179 |
180 | private void btnGESnap_Click(object sender, EventArgs e)
181 | {
182 | if (CheckGEState(true, "GESnap"))
183 | {
184 | using (SaveFileDialog sfd = new SaveFileDialog())
185 | {
186 | sfd.Filter = "JPEG图片(*.jpg)|*.jpg";
187 | sfd.AddExtension = true;
188 | sfd.CheckPathExists = true;
189 | sfd.Title = "保存Google Earth截图";
190 |
191 | if (sfd.ShowDialog() == DialogResult.OK)
192 | {
193 | GEApp.SaveScreenShot(sfd.FileName, 100);
194 | msgToolTip.Show("\'" + sfd.FileName + "\' Saved", tabGEViewer, tabGEViewer.Width / 4, tabGEViewer.Height / 4, 2000);
195 | }
196 | }
197 | }
198 | }
199 |
200 | private void btnAPISnap_Click(object sender, EventArgs e)
201 | {
202 | if (CheckGEState(true, "APISnap"))
203 | {
204 | RECT rect = new RECT();
205 | NativeMethods.GetClientRect(GEHRenderWnd, out rect);
206 |
207 | // 取得Render DC
208 | IntPtr hRenderDC = NativeMethods.GetWindowDC(GEHRenderWnd);
209 | // 创建hBitmap
210 | IntPtr hBitmap = NativeMethods.CreateCompatibleBitmap(hRenderDC, rect.Width, rect.Height);
211 | // 创建MEM DC
212 | IntPtr hMemDC = NativeMethods.CreateCompatibleDC(hRenderDC);
213 | // 将Bitmap Select到MemDC
214 | NativeMethods.SelectObject(hMemDC, hBitmap);
215 | // 直接拷屏
216 | NativeMethods.BitBlt(hMemDC, rect.left, rect.top, rect.Width, rect.Height, hRenderDC, 0, 0, NativeMethods.SRCCOPY);
217 |
218 | #region SaveImage
219 |
220 | using (Bitmap bmp = Bitmap.FromHbitmap(hBitmap))
221 | {
222 | using (SaveFileDialog sfd = new SaveFileDialog())
223 | {
224 | sfd.Filter = "JPEG图片(*.jpg)|*.jpg|PNG图片(*.png)|*.png";
225 | sfd.AddExtension = true;
226 | sfd.CheckPathExists = true;
227 | sfd.Title = "保存Google Earth截图";
228 |
229 | if (sfd.ShowDialog() == DialogResult.OK)
230 | {
231 | ImageFormat imgFormat = null;
232 | // 默认选择JPG
233 | if (sfd.FilterIndex == 0)
234 | {
235 | imgFormat = ImageFormat.Jpeg;
236 | }
237 | // 选择PNG
238 | else
239 | {
240 | imgFormat = ImageFormat.Png;
241 | }
242 | bmp.Save(sfd.FileName, imgFormat);
243 | msgToolTip.Show("\'" + sfd.FileName + "\' Saved", tabGEViewer, tabGEViewer.Width / 4, tabGEViewer.Height / 4, 2000);
244 | }
245 | }
246 | //销毁资源
247 | NativeMethods.DeleteDC(hRenderDC);
248 | NativeMethods.DeleteDC(hMemDC);
249 | }
250 |
251 | #endregion SaveImage
252 | }
253 |
254 | }
255 |
256 | private void btnParamsSettings_Click(object sender, EventArgs e)
257 | {
258 | if (CheckGEState(true, "Setting Camera Parameters"))
259 | {
260 | tabDocker.TabPages.Add(tabXPViewer);
261 | tabDocker.SelectTab(tabXPViewer);
262 | }
263 | }
264 |
265 | private void btnOKCamParams_Click(object sender, EventArgs e)
266 | {
267 | GetParamsValue();
268 | if (CheckInputParams())
269 | {
270 | GEApp.SetCameraParams(scp.dLat, scp.dLon, scp.dAlt,
271 | AltitudeModeGE.AbsoluteAltitudeGE,
272 | scp.dRng, scp.dAng, scp.dAzm, scp.dSpd);
273 | tabDocker.TabPages.Remove(tabXPViewer);
274 | }
275 | else
276 | {
277 | MessageBox.Show("Invalid Parameters!");
278 | }
279 | }
280 |
281 | #endregion MessageHandlers
282 |
283 | #region AuxFunctions
284 |
285 | private bool CheckGEState(bool bExpRun, string caption)
286 | {
287 | bool state = true;
288 | if (bExpRun)
289 | {
290 | //期望GE运行而实际并未运行
291 | if (!isGEStarted)
292 | {
293 | MessageBox.Show("Goolge Earth is not running", caption);
294 | state = false;
295 | }
296 | }
297 | else
298 | {
299 | //期望GE关闭而实际正在运行
300 | if (isGEStarted)
301 | {
302 | MessageBox.Show("Goolge Earth is running currently", caption);
303 | state = false;
304 | }
305 | }
306 |
307 | return state;
308 | }
309 |
310 | //reset=true表示清除背景图片
311 | private void SetBackgroundImage(Control control, bool reset = false)
312 | {
313 | if (reset)
314 | {
315 | control.BackgroundImage = null;
316 | }
317 | else
318 | {
319 | control.BackgroundImage = Properties.Resources.GEBgnd;
320 | control.BackgroundImageLayout = ImageLayout.Stretch;
321 | }
322 | }
323 |
324 | private void GetParamsValue()
325 | {
326 | scp.dLat = TranslateLatLon(txtBoxLat.Text);
327 | scp.dLon = TranslateLatLon(txtBoxLon.Text);
328 | scp.dAlt = double.Parse(txtBoxAlt.Text);
329 | scp.dRng = double.Parse(txtBoxRng.Text);
330 | scp.dAng = double.Parse(txtBoxAng.Text);
331 | scp.dAzm = double.Parse(txtBoxAzm.Text);
332 | scp.dSpd = double.Parse(txtBoxSpd.Text);
333 | }
334 |
335 | private void SetParamsDefault()
336 | {
337 | // 上海外滩,东方明珠塔
338 | // (31°14'30''N 121°29'43''E)
339 | // (31.24167°N 121.4953°E)
340 |
341 | txtBoxLat.Text = "31°14'30''N";
342 | txtBoxLon.Text = "121°29'43''E";
343 | txtBoxAlt.Text = "0";
344 | txtBoxRng.Text = "2000";
345 | txtBoxAng.Text = "0";
346 | txtBoxAzm.Text = "0";
347 | txtBoxSpd.Text = "3";
348 |
349 | scp.dLat = 31.24167;
350 | scp.dLon = 121.4953;
351 | scp.dAlt = 0;
352 | scp.dRng = 2000;
353 | scp.dAng = 0;
354 | scp.dAzm = 0;
355 | scp.dSpd = 3;
356 | }
357 |
358 | private bool CheckInputParams()
359 | {
360 | return (scp.dLat >= -90 && scp.dLat <= 90)&&
361 | (scp.dLon >= -180 && scp.dLon <= 180)&&
362 | (scp.dAlt >= 0) && (scp.dRng>0)&&
363 | (scp.dAng >= 0)&& (scp.dSpd > 0);
364 | }
365 |
366 | public double TranslateLatLon(string slatlon)
367 | {
368 | double ddeg = 0.0;
369 | double dmin = 0.0;
370 | double dsec = 0.0;
371 | int start=0,pos=0;
372 | #region VAL
373 | pos = slatlon.IndexOf('°',start);
374 | if (pos > 0)
375 | {
376 | #region ddeg
377 | while (start 0)
391 | {
392 | #region dmin
393 | while (start < pos)
394 | {
395 | if (slatlon[start] == '0') ++start;
396 | else break;
397 | }
398 | if (start < pos-1)
399 | {
400 | dmin = double.Parse(slatlon.Substring(start, pos - start));
401 | }
402 | #endregion dmin
403 |
404 | start = pos + 1;
405 | pos = slatlon.IndexOf('\'', start);
406 | if (pos > 0)
407 | {
408 | #region dsec
409 | while (start < pos)
410 | {
411 | if (slatlon[start] == '0') ++start;
412 | else break;
413 | }
414 | if (start < pos-1)
415 | {
416 | dsec = double.Parse(slatlon.Substring(start, pos - start));
417 | }
418 | #endregion dsec
419 | } //if(pos,dsec)
420 | } //if(pos,dmin)
421 | #region SGN
422 | pos =slatlon.LastIndexOf('\'')+ 1;
423 | if (slatlon[pos] == 'S'||slatlon[pos]=='W')
424 | {
425 | ddeg = -ddeg;
426 | dmin = -dmin;
427 | dsec = -dsec;
428 | } //if(pos,len-1)
429 | #endregion SGN
430 | } //if(pos ddeg)
431 | else
432 | {
433 | ddeg = double.Parse(slatlon);
434 | }
435 | #endregion VAL
436 |
437 | return (ddeg + dmin / 60.0 + dsec / 3600.0);
438 | }
439 |
440 | #endregion AuxFunctions
441 |
442 | }
443 |
444 | }
445 |
--------------------------------------------------------------------------------
/GEDemo5/GEDemo5.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {CF675AD5-E0EF-415E-A120-A9340E5D24B4}
8 | WinExe
9 | Properties
10 | GEDemo5
11 | GEDemo5
12 | v2.0
13 | 512
14 |
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | x86
28 | pdbonly
29 | true
30 | ..\bin\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 | Resources\GEApp.ico
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | Form
49 |
50 |
51 | GEDemo5.cs
52 |
53 |
54 |
55 |
56 |
57 |
58 | GEDemo5.cs
59 |
60 |
61 | ResXFileCodeGenerator
62 | Designer
63 | Resources.Designer.cs
64 |
65 |
66 |
67 | SettingsSingleFileGenerator
68 | Settings.Designer.cs
69 |
70 |
71 | True
72 | True
73 | Resources.resx
74 |
75 |
76 | True
77 | Settings.settings
78 | True
79 |
80 |
81 |
82 |
83 | {3476FAB2-687F-4EA6-9AC2-88D72DC7D7FC}
84 | 1
85 | 0
86 | 0
87 | tlbimp
88 | False
89 | True
90 |
91 |
92 | {00020430-0000-0000-C000-000000000046}
93 | 2
94 | 0
95 | 0
96 | primary
97 | False
98 | True
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
121 |
--------------------------------------------------------------------------------
/GEDemo5/NativeMethods.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 | using System.Runtime.InteropServices;
4 | using System.Drawing;
5 |
6 | namespace GEDemo5
7 | {
8 | public class NativeMethods
9 | {
10 | [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
11 | public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, UInt32 uflags);
12 |
13 | [DllImport("user32.dll", CharSet = CharSet.Auto)]
14 | public static extern IntPtr PostMessage(IntPtr hWnd, int msg, int wParam, int lParam);
15 | [DllImport("user32.dll")]
16 | public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
17 | [DllImport("user32.dll", CharSet = CharSet.Auto)]
18 | public static extern int GetMessage(out MSG msg, IntPtr hWnd, int wMsgFilterMin, int wMsgFilterMax);
19 | [DllImport("user32.dll", CharSet = CharSet.Auto)]
20 | public static extern int PeekMessage(out MSG msg, IntPtr hWnd, int wMsgFilterMin, int wMsgFilterMax);
21 | [DllImport("user32.dll", CharSet = CharSet.Auto)]
22 | public static extern long DispatchMessage(MSG msg);
23 |
24 | [DllImport("user32.dll")]
25 | public static extern IntPtr FindWindow(string className, string windowTitle);
26 | [DllImport("user32.dll")]
27 | public static extern bool ShowWindowAsync(int hWnd, int nCmdShow);
28 |
29 | [DllImport("user32.dll")]
30 | public static extern bool GetWindowRect(IntPtr hWnd, out RECT rect);
31 |
32 | [DllImport("user32.dll")]
33 | public static extern bool GetClientRect(IntPtr hWnd, out RECT rect);
34 |
35 | [DllImport("user32.dll")]
36 | public static extern IntPtr GetDesktopWindow();
37 |
38 | [DllImport("user32")]
39 | public static extern IntPtr GetWindowDC(IntPtr hwnd);
40 |
41 | [DllImport("user32")]
42 | public static extern IntPtr GetDC(IntPtr hwnd);
43 |
44 | [DllImport("user32")]
45 | public static extern long ReleaseDC(IntPtr handle, IntPtr hdc);
46 |
47 | [DllImport("user32")]
48 | public static extern IntPtr WindowFromPoint(Point point);
49 |
50 | [DllImport("user32")]
51 | public static extern bool PrintWindow(IntPtr hWnd, IntPtr hdcBlt, UInt32 nFlags);
52 |
53 | [DllImport("kernel32.dll", SetLastError = true)]
54 | [return: MarshalAs(UnmanagedType.Bool)]
55 | public static extern bool CloseHandle(IntPtr hObject);
56 |
57 | #region 预定义
58 |
59 | public static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
60 | public static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
61 | public static readonly IntPtr HWND_TOP = new IntPtr(0);
62 | public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
63 | public static readonly uint SWP_NOSIZE = 1U;
64 | public static readonly uint SWP_NOMOVE = 2U;
65 | public static readonly uint SWP_NOZORDER = 4U;
66 | public static readonly uint SWP_NOREDRAW = 8U;
67 | public static readonly uint SWP_NOACTIVATE = 16U;
68 | public static readonly uint SWP_FRAMECHANGED = 32U;
69 | public static readonly uint SWP_SHOWWINDOW = 64U;
70 | public static readonly uint SWP_HIDEWINDOW = 128U;
71 | public static readonly uint SWP_NOCOPYBITS = 256U;
72 | public static readonly uint SWP_NOOWNERZORDER = 512U;
73 | public static readonly uint SWP_NOSENDCHANGING = 1024U;
74 | public static readonly int WM_COMMAND = 0x0112;
75 | public static readonly int WM_QT_PAINT = 0xC2DC;
76 | public static readonly int WM_PAINT = 0x000F;
77 | public static readonly int WM_SIZE = 0x0005;
78 | public static readonly int SRCCOPY = 0xCC0020;
79 |
80 | #endregion
81 |
82 | public delegate int EnumWindowsProc(IntPtr hWnd, int lParam);
83 |
84 | [DllImport("user32", CharSet = CharSet.Auto)]
85 | public extern static IntPtr GetParent(IntPtr hWnd);
86 |
87 | [DllImport("user32", CharSet = CharSet.Auto)]
88 | public extern static bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
89 |
90 | [DllImport("user32", CharSet = CharSet.Auto)]
91 | public extern static IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
92 |
93 | [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
94 | public static extern IntPtr GetWindow(IntPtr hWnd, int uCmd);
95 |
96 | public static int GW_CHILD = 5;
97 | public static int GW_HWNDNEXT = 2;
98 |
99 | #region GDI绘图函数
100 |
101 | [DllImport("gdi32.dll")]
102 | public static extern IntPtr CreateCompatibleDC(IntPtr hwnd);
103 |
104 | [DllImport("gdi32.dll")]
105 | public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidht, int nHeight);
106 |
107 | [DllImport("gdi32.dll")]
108 | public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
109 |
110 | [DllImport("gdi32.dll")]
111 | public static extern int DeleteDC(IntPtr hdc);
112 |
113 | [DllImport("gdi32.dll")]
114 | public static extern IntPtr CreateDC(string lpszDriver, string lpszDevice, string lpszOutput, IntPtr lpInitData);
115 | ///
116 | /// API函数BitBlt
117 | ///
118 | /// DC目标设备句柄
119 | /// 目标对象的左上角X坐标
120 | /// 目标对象的左上角Y坐标
121 | /// 目标对象的矩形宽度
122 | /// 目标对象的矩形高度
123 | /// DC源设备句柄
124 | /// 源对象的左上角X坐标
125 | /// 源对象的左上角Y坐标
126 | /// 光栅操作值
127 | ///
128 | [DllImport("gdi32.dll")]
129 | public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
130 | ///
131 | /// 使用当前选定的画笔和画刷进行矩形的绘制
132 | ///
133 | /// DC句柄
134 | /// 左上角x坐标
135 | /// 左上角y坐标
136 | /// 右下角x坐标
137 | /// 右下角y坐标
138 | ///
139 | [DllImport("gdi32.dll")]
140 | public static extern bool Rectangle(IntPtr hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
141 |
142 | #region Raster operation(BitBlt函数最后一个参数)
143 | ///
144 | /// 以黑色填充目标矩形区域。
145 | ///
146 | public static int RP_BLACKNESS = 0x42;
147 | ///
148 | /// 先将源矩形图像与目标矩形图像进行布尔“或”运算,然后再将图像进行反相。
149 | ///
150 | public static int RP_NOTSRCERASE = 0x001100A6;
151 | ///
152 | /// 将源矩形图像进行反相,复制到目标矩形上。
153 | ///
154 | public static int RP_NOTSRCCOPY = 0x330008;
155 | ///
156 | /// 将目标矩形图像进行反相.
157 | ///
158 | public static int RP_DSTINVERT = 0x550009;
159 | ///
160 | /// 将源矩形图像进行反相,与目标矩形图像进行布尔“或”运算。
161 | ///
162 | public static int RP_MERGEPAINT = 0x0BB0226;
163 | ///
164 | /// 将源矩形图像与指定的图案刷(Pattern)进行布尔“与”运算
165 | ///
166 | public static int RP_MERGECOPY = 0x00C000CA;
167 | ///
168 | /// 将源矩形图像与目标矩形图像进行布尔“与”运算。
169 | ///
170 | public static int RP_SRCAND = 0x008800C6;
171 | ///
172 | /// 将目标矩形图像直接复制到目标矩形。
173 | ///
174 | public static int RP_SRCCOPY = 0x00CC0020;
175 | ///
176 | /// 将目标矩形图像进行反相,再与源矩形图像进行布尔“与”运算。
177 | ///
178 | public static int RP_SRCERASE = 0x440328;
179 | ///
180 | /// 将源矩形图像与目标矩形图像进行布尔“或”运算。
181 | ///
182 | public static int RP_SRCPAINT = 0x00EE0086;
183 | ///
184 | /// 将源矩形图像与目标矩形图像进行布尔“异或”运算。
185 | ///
186 | public static int RP_SRCINVERT = 0x660046;
187 | ///
188 | /// 将指定的图案刷复制到目标矩形上。
189 | ///
190 | public static int RP_PATCOPY = 0x00F00021;
191 | ///
192 | /// 将指定的图案刷与目标矩形图像进行布尔“异或”运算。
193 | ///
194 | public static int RP_PATINVERT = 0x005A0049;
195 | ///
196 | /// 先将源矩形图像进行反相,与指定的图案刷进行布尔“或”运算,再与目标矩形图像进行布尔“或”运算
197 | ///
198 | public static int RP_PATPAINT = 0x00FB0A09;
199 | ///
200 | /// 用白色填充矩形区域。
201 | ///
202 | public static int RP_WHITENESS = 0x00FF0062;
203 | #endregion
204 |
205 | #endregion
206 | }
207 | }
--------------------------------------------------------------------------------
/GEDemo5/NativeStructure.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace GEDemo5
6 | {
7 | [StructLayout(LayoutKind.Sequential)]
8 | public class POINT
9 | {
10 | public int x;
11 | public int y;
12 |
13 | public POINT()
14 | {
15 | }
16 |
17 | public POINT(int x, int y)
18 | {
19 | this.x = x;
20 | this.y = y;
21 | }
22 | }
23 |
24 | [StructLayout(LayoutKind.Sequential)]
25 | public class POINTD
26 | {
27 | private double x;
28 | private double y;
29 | public double X
30 | {
31 | get { return this.x; }
32 | set { this.x = value; }
33 | }
34 | public double Y
35 | {
36 | get { return this.y; }
37 | set { this.y = value; }
38 | }
39 |
40 | public POINTD()
41 | {
42 | x = -1.0;
43 | y = -1.0;
44 | }
45 |
46 | public POINTD(double dx, double dy)
47 | {
48 | x = dx;
49 | y = dy;
50 | }
51 | }
52 |
53 | [StructLayout(LayoutKind.Sequential)]
54 | public struct RECT
55 | {
56 | public int left;
57 | public int top;
58 | public int Width;
59 | public int Height;
60 | }
61 |
62 | [StructLayout(LayoutKind.Sequential)]
63 | public struct SCROLLINFO
64 | {
65 | public uint cbSize;
66 | public uint fMask;
67 | public int nMin;
68 | public int nMax;
69 | public uint nPage;
70 | public int nPos;
71 | public int nTrackPos;
72 | }
73 |
74 | [StructLayout(LayoutKind.Sequential)]
75 | public struct MSG
76 | {
77 | public IntPtr hwnd;
78 |
79 | public uint message;
80 |
81 | public IntPtr WPARAM;
82 |
83 | public IntPtr LPARAM;
84 |
85 | public long Time;
86 |
87 | public POINT pt;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/GEDemo5/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | namespace GEDemo5
5 | {
6 | static class Program
7 | {
8 | ///
9 | /// 应用程序的主入口点。
10 | ///
11 | [STAThread]
12 | static void Main()
13 | {
14 | Application.EnableVisualStyles();
15 | Application.SetCompatibleTextRenderingDefault(false);
16 | Application.Run(new GEDemo5());
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/GEDemo5/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("GEDemo5")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("GEDemo5")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("7da38045-20bf-4375-aab3-d1b7a02e3570")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/GEDemo5/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.18408
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace GEDemo5.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// 一个强类型的资源类,用于查找本地化的字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// 返回此类使用的缓存的 ResourceManager 实例。
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GEDemo5.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// 使用此强类型资源类,为所有资源查找
51 | /// 重写当前线程的 CurrentUICulture 属性。
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// 查找类似于 (Icon) 的 System.Drawing.Icon 类型的本地化资源。
65 | ///
66 | internal static System.Drawing.Icon GEApp {
67 | get {
68 | object obj = ResourceManager.GetObject("GEApp", resourceCulture);
69 | return ((System.Drawing.Icon)(obj));
70 | }
71 | }
72 |
73 | ///
74 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。
75 | ///
76 | internal static System.Drawing.Bitmap GEBgnd {
77 | get {
78 | object obj = ResourceManager.GetObject("GEBgnd", resourceCulture);
79 | return ((System.Drawing.Bitmap)(obj));
80 | }
81 | }
82 |
83 | ///
84 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。
85 | ///
86 | internal static System.Drawing.Bitmap GESnap {
87 | get {
88 | object obj = ResourceManager.GetObject("GESnap", resourceCulture);
89 | return ((System.Drawing.Bitmap)(obj));
90 | }
91 | }
92 |
93 | ///
94 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。
95 | ///
96 | internal static System.Drawing.Bitmap GEStart {
97 | get {
98 | object obj = ResourceManager.GetObject("GEStart", resourceCulture);
99 | return ((System.Drawing.Bitmap)(obj));
100 | }
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/GEDemo5/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 |
122 | ..\Resources\GEApp.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
123 |
124 |
125 | ..\Resources\GEBgnd.jpg;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
126 |
127 |
128 | ..\Resources\GESnap.jpg;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
129 |
130 |
131 | ..\Resources\GEStart.jpg;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
132 |
133 |
--------------------------------------------------------------------------------
/GEDemo5/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18408
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace GEDemo5.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/GEDemo5/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/GEDemo5/Resources/GEApp.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengyhack/LearningGoogleEarthNET/4a3c04ecc754385e56e5b1cb24e37aed835de6b9/GEDemo5/Resources/GEApp.ico
--------------------------------------------------------------------------------
/GEDemo5/Resources/GEBgnd.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengyhack/LearningGoogleEarthNET/4a3c04ecc754385e56e5b1cb24e37aed835de6b9/GEDemo5/Resources/GEBgnd.jpg
--------------------------------------------------------------------------------
/GEDemo5/Resources/GESnap.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengyhack/LearningGoogleEarthNET/4a3c04ecc754385e56e5b1cb24e37aed835de6b9/GEDemo5/Resources/GESnap.jpg
--------------------------------------------------------------------------------
/GEDemo5/Resources/GEStart.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengyhack/LearningGoogleEarthNET/4a3c04ecc754385e56e5b1cb24e37aed835de6b9/GEDemo5/Resources/GEStart.jpg
--------------------------------------------------------------------------------
/GEDemo5/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Learning Google Earth .NET
2 |
3 | Google Earth COM API Demos (C#)
4 |
--------------------------------------------------------------------------------