├── .gitignore
├── LICENSE
├── README.md
├── RemoteWebBrowser.sln
├── RemoteWebBrowser
├── App.config
├── Form_Main.Designer.cs
├── Form_Main.cs
├── Form_Main.resx
├── Program.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── RemoteWebBrowser.csproj
├── TabBrowser.Designer.cs
├── TabBrowser.cs
├── TabBrowser.resx
└── icon.ico
├── RemoteWebBrowserClient
├── App.config
├── BrowserService.cs
├── Form_Main.Designer.cs
├── Form_Main.cs
├── Form_Main.resx
├── Program.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── RemoteWebBrowserClient.csproj
└── icon.ico
├── RemoteWebBrowserServer
├── App.config
├── BrowserService.cs
├── Form_Main.Designer.cs
├── Form_Main.cs
├── Form_Main.resx
├── Packet.cs
├── Program.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── RemoteWebBrowserServer.csproj
├── WinApi.cs
└── icon.ico
└── Resources
├── demo.PNG
├── desc.png
└── icon.ico
/.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 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | build/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opensdf
80 | *.sdf
81 | *.cachefile
82 |
83 | # Visual Studio profiler
84 | *.psess
85 | *.vsp
86 | *.vspx
87 | *.sap
88 |
89 | # TFS 2012 Local Workspace
90 | $tf/
91 |
92 | # Guidance Automation Toolkit
93 | *.gpState
94 |
95 | # ReSharper is a .NET coding add-in
96 | _ReSharper*/
97 | *.[Rr]e[Ss]harper
98 | *.DotSettings.user
99 |
100 | # JustCode is a .NET coding add-in
101 | .JustCode
102 |
103 | # TeamCity is a build add-in
104 | _TeamCity*
105 |
106 | # DotCover is a Code Coverage Tool
107 | *.dotCover
108 |
109 | # NCrunch
110 | _NCrunch_*
111 | .*crunch*.local.xml
112 | nCrunchTemp_*
113 |
114 | # MightyMoose
115 | *.mm.*
116 | AutoTest.Net/
117 |
118 | # Web workbench (sass)
119 | .sass-cache/
120 |
121 | # Installshield output folder
122 | [Ee]xpress/
123 |
124 | # DocProject is a documentation generator add-in
125 | DocProject/buildhelp/
126 | DocProject/Help/*.HxT
127 | DocProject/Help/*.HxC
128 | DocProject/Help/*.hhc
129 | DocProject/Help/*.hhk
130 | DocProject/Help/*.hhp
131 | DocProject/Help/Html2
132 | DocProject/Help/html
133 |
134 | # Click-Once directory
135 | publish/
136 |
137 | # Publish Web Output
138 | *.[Pp]ublish.xml
139 | *.azurePubxml
140 | # TODO: Comment the next line if you want to checkin your web deploy settings
141 | # but database connection strings (with potential passwords) will be unencrypted
142 | *.pubxml
143 | *.publishproj
144 |
145 | # NuGet Packages
146 | *.nupkg
147 | # The packages folder can be ignored because of Package Restore
148 | **/packages/*
149 | # except build/, which is used as an MSBuild target.
150 | !**/packages/build/
151 | # Uncomment if necessary however generally it will be regenerated when needed
152 | #!**/packages/repositories.config
153 |
154 | # Windows Azure Build Output
155 | csx/
156 | *.build.csdef
157 |
158 | # Windows Azure Emulator
159 | efc/
160 | rfc/
161 |
162 | # Windows Store app package directory
163 | AppPackages/
164 |
165 | # Visual Studio cache files
166 | # files ending in .cache can be ignored
167 | *.[Cc]ache
168 | # but keep track of directories ending in .cache
169 | !*.[Cc]ache/
170 |
171 | # Others
172 | ClientBin/
173 | [Ss]tyle[Cc]op.*
174 | ~$*
175 | *~
176 | *.dbmdl
177 | *.dbproj.schemaview
178 | *.pfx
179 | *.publishsettings
180 | node_modules/
181 | orleans.codegen.cs
182 |
183 | # RIA/Silverlight projects
184 | Generated_Code/
185 |
186 | # Backup & report files from converting an old project file
187 | # to a newer Visual Studio version. Backup files are not needed,
188 | # because we have git ;-)
189 | _UpgradeReport_Files/
190 | Backup*/
191 | UpgradeLog*.XML
192 | UpgradeLog*.htm
193 |
194 | # SQL Server files
195 | *.mdf
196 | *.ldf
197 |
198 | # Business Intelligence projects
199 | *.rdl.data
200 | *.bim.layout
201 | *.bim_*.settings
202 |
203 | # Microsoft Fakes
204 | FakesAssemblies/
205 |
206 | # GhostDoc plugin setting file
207 | *.GhostDoc.xml
208 |
209 | # Node.js Tools for Visual Studio
210 | .ntvs_analysis.dat
211 |
212 | # Visual Studio 6 build log
213 | *.plg
214 |
215 | # Visual Studio 6 workspace options file
216 | *.opt
217 |
218 | # Visual Studio LightSwitch build output
219 | **/*.HTMLClient/GeneratedArtifacts
220 | **/*.DesktopClient/GeneratedArtifacts
221 | **/*.DesktopClient/ModelManifest.xml
222 | **/*.Server/GeneratedArtifacts
223 | **/*.Server/ModelManifest.xml
224 | _Pvt_Extensions
225 |
226 | # Paket dependency manager
227 | .paket/paket.exe
228 |
229 | # FAKE - F# Make
230 | .fake/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 NeuroWhAI
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Remote Web Browser
2 |
3 | 
4 |
5 | ## Diagram
6 |
7 | 
8 |
9 | ## Demo
10 |
11 | 
12 |
13 | ## Why?
14 |
15 | 😏
16 |
--------------------------------------------------------------------------------
/RemoteWebBrowser.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26430.15
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoteWebBrowserServer", "RemoteWebBrowserServer\RemoteWebBrowserServer.csproj", "{2D7DA974-14FB-4F9A-9C16-15022579135C}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoteWebBrowser", "RemoteWebBrowser\RemoteWebBrowser.csproj", "{54218053-9402-4ABE-99E1-A7F83410198E}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoteWebBrowserClient", "RemoteWebBrowserClient\RemoteWebBrowserClient.csproj", "{0E2EE8B8-CEA1-45C9-BC97-A35FB87FAA9B}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {2D7DA974-14FB-4F9A-9C16-15022579135C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {2D7DA974-14FB-4F9A-9C16-15022579135C}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {2D7DA974-14FB-4F9A-9C16-15022579135C}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {2D7DA974-14FB-4F9A-9C16-15022579135C}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {54218053-9402-4ABE-99E1-A7F83410198E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {54218053-9402-4ABE-99E1-A7F83410198E}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {54218053-9402-4ABE-99E1-A7F83410198E}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {54218053-9402-4ABE-99E1-A7F83410198E}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {0E2EE8B8-CEA1-45C9-BC97-A35FB87FAA9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {0E2EE8B8-CEA1-45C9-BC97-A35FB87FAA9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {0E2EE8B8-CEA1-45C9-BC97-A35FB87FAA9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {0E2EE8B8-CEA1-45C9-BC97-A35FB87FAA9B}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | EndGlobal
35 |
--------------------------------------------------------------------------------
/RemoteWebBrowser/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/RemoteWebBrowser/Form_Main.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace RemoteWebBrowser
2 | {
3 | partial class Form_Main
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 Form 디자이너에서 생성한 코드
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(Form_Main));
33 | this.tabControl_web = new System.Windows.Forms.TabControl();
34 | this.tabPage_newTab = new System.Windows.Forms.TabPage();
35 | this.contextMenuStrip_tab = new System.Windows.Forms.ContextMenuStrip(this.components);
36 | this.ToolStripMenuItem_close = new System.Windows.Forms.ToolStripMenuItem();
37 | this.tabControl_web.SuspendLayout();
38 | this.contextMenuStrip_tab.SuspendLayout();
39 | this.SuspendLayout();
40 | //
41 | // tabControl_web
42 | //
43 | this.tabControl_web.Controls.Add(this.tabPage_newTab);
44 | this.tabControl_web.Dock = System.Windows.Forms.DockStyle.Fill;
45 | this.tabControl_web.HotTrack = true;
46 | this.tabControl_web.Location = new System.Drawing.Point(0, 0);
47 | this.tabControl_web.Multiline = true;
48 | this.tabControl_web.Name = "tabControl_web";
49 | this.tabControl_web.SelectedIndex = 0;
50 | this.tabControl_web.Size = new System.Drawing.Size(784, 561);
51 | this.tabControl_web.TabIndex = 0;
52 | this.tabControl_web.SelectedIndexChanged += new System.EventHandler(this.tabControl_web_SelectedIndexChanged);
53 | //
54 | // tabPage_newTab
55 | //
56 | this.tabPage_newTab.Location = new System.Drawing.Point(4, 22);
57 | this.tabPage_newTab.Name = "tabPage_newTab";
58 | this.tabPage_newTab.Size = new System.Drawing.Size(776, 535);
59 | this.tabPage_newTab.TabIndex = 0;
60 | this.tabPage_newTab.Tag = "+";
61 | this.tabPage_newTab.Text = "새 탭";
62 | this.tabPage_newTab.ToolTipText = "+";
63 | this.tabPage_newTab.UseVisualStyleBackColor = true;
64 | //
65 | // contextMenuStrip_tab
66 | //
67 | this.contextMenuStrip_tab.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
68 | this.ToolStripMenuItem_close});
69 | this.contextMenuStrip_tab.Name = "contextMenuStrip_tab";
70 | this.contextMenuStrip_tab.Size = new System.Drawing.Size(167, 26);
71 | //
72 | // ToolStripMenuItem_close
73 | //
74 | this.ToolStripMenuItem_close.Name = "ToolStripMenuItem_close";
75 | this.ToolStripMenuItem_close.Size = new System.Drawing.Size(166, 22);
76 | this.ToolStripMenuItem_close.Text = "현재 페이지 닫기";
77 | this.ToolStripMenuItem_close.Click += new System.EventHandler(this.ToolStripMenuItem_close_Click);
78 | //
79 | // Form_Main
80 | //
81 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
82 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
83 | this.ClientSize = new System.Drawing.Size(784, 561);
84 | this.Controls.Add(this.tabControl_web);
85 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
86 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
87 | this.Name = "Form_Main";
88 | this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
89 | this.Text = "Remote Web Browser";
90 | this.Load += new System.EventHandler(this.Form_Main_Load);
91 | this.tabControl_web.ResumeLayout(false);
92 | this.contextMenuStrip_tab.ResumeLayout(false);
93 | this.ResumeLayout(false);
94 |
95 | }
96 |
97 | #endregion
98 |
99 | private System.Windows.Forms.TabControl tabControl_web;
100 | private System.Windows.Forms.ContextMenuStrip contextMenuStrip_tab;
101 | private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_close;
102 | private System.Windows.Forms.TabPage tabPage_newTab;
103 | }
104 | }
105 |
106 |
--------------------------------------------------------------------------------
/RemoteWebBrowser/Form_Main.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Forms;
10 |
11 | namespace RemoteWebBrowser
12 | {
13 | public partial class Form_Main : Form
14 | {
15 | public Form_Main()
16 | {
17 | InitializeComponent();
18 | }
19 |
20 | //###########################################################################################################################
21 |
22 | private void Form_Main_Load(object sender, EventArgs e)
23 | {
24 | CreateNewTab();
25 | }
26 |
27 | private TabBrowser CreateNewTab()
28 | {
29 | TabPage tab = new TabPage();
30 |
31 |
32 | var browser = new TabBrowser();
33 | browser.Location = new Point(0, 0);
34 | browser.Dock = DockStyle.Fill;
35 |
36 | browser.WhenDocumentCompleted += (string title, string uri) =>
37 | {
38 | tab.Text = (title.Length == 0 ? "null" : title);
39 | tab.ToolTipText = uri;
40 | };
41 |
42 | browser.WhenPopup += (string uri) =>
43 | {
44 | var popup = CreateNewTab();
45 | popup.Navigate(uri);
46 |
47 | this.tabControl_web.SelectedIndex = this.tabControl_web.TabCount - 2;
48 | };
49 |
50 |
51 | tab.Controls.Add(browser);
52 |
53 | this.tabControl_web.TabPages.Insert(this.tabControl_web.TabCount - 1, tab);
54 |
55 | this.tabControl_web.SelectedTab = tab;
56 |
57 |
58 | return browser;
59 | }
60 |
61 | private void tabControl_web_SelectedIndexChanged(object sender, EventArgs e)
62 | {
63 | if (this.tabControl_web.SelectedTab.Tag as string == "+")
64 | {
65 | CreateNewTab();
66 | }
67 | else if (this.tabControl_web.TabCount > 2)
68 | {
69 | this.contextMenuStrip_tab.Show(this.tabControl_web.SelectedTab, 0, 0);
70 | }
71 | }
72 |
73 | private void ToolStripMenuItem_close_Click(object sender, EventArgs e)
74 | {
75 | this.tabControl_web.TabPages.RemoveAt(this.tabControl_web.SelectedIndex);
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/RemoteWebBrowser/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using System.Windows.Forms;
6 |
7 | namespace RemoteWebBrowser
8 | {
9 | static class Program
10 | {
11 | ///
12 | /// 해당 응용 프로그램의 주 진입점입니다.
13 | ///
14 | [STAThread]
15 | static void Main()
16 | {
17 | Application.EnableVisualStyles();
18 | Application.SetCompatibleTextRenderingDefault(false);
19 | Application.Run(new Form_Main());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/RemoteWebBrowser/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해
6 | // 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
7 | // 이러한 특성 값을 변경하세요.
8 | [assembly: AssemblyTitle("RemoteWebBrowser")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("RemoteWebBrowser")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
18 | // 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
19 | // 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
20 | [assembly: ComVisible(false)]
21 |
22 | // 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
23 | [assembly: Guid("54218053-9402-4abe-99e1-a7f83410198e")]
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 |
--------------------------------------------------------------------------------
/RemoteWebBrowser/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 이 코드는 도구를 사용하여 생성되었습니다.
4 | // 런타임 버전:4.0.30319.42000
5 | //
6 | // 파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면
7 | // 이러한 변경 내용이 손실됩니다.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace RemoteWebBrowser.Properties
12 | {
13 |
14 |
15 | ///
16 | /// 지역화된 문자열 등을 찾기 위한 강력한 형식의 리소스 클래스입니다.
17 | ///
18 | // 이 클래스는 ResGen 또는 Visual Studio와 같은 도구를 통해 StronglyTypedResourceBuilder
19 | // 클래스에서 자동으로 생성되었습니다.
20 | // 멤버를 추가하거나 제거하려면 .ResX 파일을 편집한 다음 /str 옵션을 사용하여
21 | // ResGen을 다시 실행하거나 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 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// 이 클래스에서 사용하는 캐시된 ResourceManager 인스턴스를 반환합니다.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("RemoteWebBrowser.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// 이 강력한 형식의 리소스 클래스를 사용하여 모든 리소스 조회에 대해
56 | /// 현재 스레드의 CurrentUICulture 속성을 재정의합니다.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/RemoteWebBrowser/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 |
--------------------------------------------------------------------------------
/RemoteWebBrowser/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
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 RemoteWebBrowser.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 |
--------------------------------------------------------------------------------
/RemoteWebBrowser/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/RemoteWebBrowser/RemoteWebBrowser.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {54218053-9402-4ABE-99E1-A7F83410198E}
8 | WinExe
9 | RemoteWebBrowser
10 | RemoteWebBrowser
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 | icon.ico
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | Form
53 |
54 |
55 | Form_Main.cs
56 |
57 |
58 |
59 |
60 | UserControl
61 |
62 |
63 | TabBrowser.cs
64 |
65 |
66 | Form_Main.cs
67 |
68 |
69 | ResXFileCodeGenerator
70 | Resources.Designer.cs
71 | Designer
72 |
73 |
74 | True
75 | Resources.resx
76 |
77 |
78 | TabBrowser.cs
79 |
80 |
81 | SettingsSingleFileGenerator
82 | Settings.Designer.cs
83 |
84 |
85 | True
86 | Settings.settings
87 | True
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 | {EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}
96 | 1
97 | 1
98 | 0
99 | tlbimp
100 | False
101 | True
102 |
103 |
104 |
105 |
106 |
107 |
108 |
--------------------------------------------------------------------------------
/RemoteWebBrowser/TabBrowser.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace RemoteWebBrowser
2 | {
3 | partial class TabBrowser
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 구성 요소 디자이너에서 생성한 코드
24 |
25 | ///
26 | /// 디자이너 지원에 필요한 메서드입니다.
27 | /// 이 메서드의 내용을 코드 편집기로 수정하지 마세요.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
32 | this.webBrowser1 = new System.Windows.Forms.WebBrowser();
33 | this.textBox_uri1 = new System.Windows.Forms.TextBox();
34 | this.button_go1 = new System.Windows.Forms.Button();
35 | this.tableLayoutPanel1.SuspendLayout();
36 | this.SuspendLayout();
37 | //
38 | // tableLayoutPanel1
39 | //
40 | this.tableLayoutPanel1.ColumnCount = 2;
41 | this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
42 | this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
43 | this.tableLayoutPanel1.Controls.Add(this.webBrowser1, 0, 1);
44 | this.tableLayoutPanel1.Controls.Add(this.textBox_uri1, 0, 0);
45 | this.tableLayoutPanel1.Controls.Add(this.button_go1, 1, 0);
46 | this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
47 | this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
48 | this.tableLayoutPanel1.Name = "tableLayoutPanel1";
49 | this.tableLayoutPanel1.RowCount = 2;
50 | this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 28F));
51 | this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
52 | this.tableLayoutPanel1.Size = new System.Drawing.Size(400, 400);
53 | this.tableLayoutPanel1.TabIndex = 1;
54 | //
55 | // webBrowser1
56 | //
57 | this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
58 | this.webBrowser1.IsWebBrowserContextMenuEnabled = false;
59 | this.webBrowser1.Location = new System.Drawing.Point(3, 31);
60 | this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
61 | this.webBrowser1.Name = "webBrowser1";
62 | this.webBrowser1.Size = new System.Drawing.Size(319, 507);
63 | this.webBrowser1.TabIndex = 1;
64 | this.webBrowser1.WebBrowserShortcutsEnabled = false;
65 | this.webBrowser1.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser1_DocumentCompleted);
66 | //
67 | // textBox_uri1
68 | //
69 | this.textBox_uri1.Dock = System.Windows.Forms.DockStyle.Fill;
70 | this.textBox_uri1.Location = new System.Drawing.Point(3, 3);
71 | this.textBox_uri1.Name = "textBox_uri1";
72 | this.textBox_uri1.Size = new System.Drawing.Size(319, 21);
73 | this.textBox_uri1.TabIndex = 0;
74 | this.textBox_uri1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox_uri1_KeyDown);
75 | //
76 | // button_go1
77 | //
78 | this.button_go1.Dock = System.Windows.Forms.DockStyle.Fill;
79 | this.button_go1.Location = new System.Drawing.Point(328, 3);
80 | this.button_go1.Name = "button_go1";
81 | this.button_go1.Size = new System.Drawing.Size(69, 22);
82 | this.button_go1.TabIndex = 2;
83 | this.button_go1.Text = "Load";
84 | this.button_go1.UseVisualStyleBackColor = true;
85 | this.button_go1.Click += new System.EventHandler(this.button_go1_Click);
86 | //
87 | // TabBrowser
88 | //
89 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
90 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
91 | this.Controls.Add(this.tableLayoutPanel1);
92 | this.Name = "TabBrowser";
93 | this.Size = new System.Drawing.Size(400, 400);
94 | this.tableLayoutPanel1.ResumeLayout(false);
95 | this.tableLayoutPanel1.PerformLayout();
96 | this.ResumeLayout(false);
97 |
98 | }
99 |
100 | #endregion
101 |
102 | private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
103 | private System.Windows.Forms.WebBrowser webBrowser1;
104 | private System.Windows.Forms.TextBox textBox_uri1;
105 | private System.Windows.Forms.Button button_go1;
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/RemoteWebBrowser/TabBrowser.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Data;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Forms;
10 |
11 | namespace RemoteWebBrowser
12 | {
13 | public partial class TabBrowser : UserControl
14 | {
15 | public TabBrowser()
16 | {
17 | InitializeComponent();
18 |
19 | this.tableLayoutPanel1.SetColumnSpan(this.webBrowser1, 2);
20 |
21 | this.webBrowser1.Navigate("about:blank"); // NOTE: 없으면 ActiveXInstance가 null로 나옴.
22 | (this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser_V1).NewWindow += webBrowser1_NewWindow;
23 | }
24 |
25 | //###########################################################################################################################
26 |
27 | public delegate void NewWindowHandler(string uri);
28 | public event NewWindowHandler WhenPopup;
29 |
30 | public delegate void DocumentCompletedHandler(string title, string uri);
31 | public event DocumentCompletedHandler WhenDocumentCompleted;
32 |
33 | //###########################################################################################################################
34 |
35 | public void Navigate(string uri)
36 | {
37 | this.webBrowser1.Navigate(uri);
38 | }
39 |
40 | //###########################################################################################################################
41 |
42 | private void textBox_uri1_KeyDown(object sender, KeyEventArgs e)
43 | {
44 | if (e.KeyCode == Keys.Return)
45 | {
46 | this.webBrowser1.Navigate(this.textBox_uri1.Text);
47 | }
48 | }
49 |
50 | private void button_go1_Click(object sender, EventArgs e)
51 | {
52 | this.webBrowser1.Navigate(this.textBox_uri1.Text);
53 | }
54 |
55 | private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
56 | {
57 | this.textBox_uri1.Text = this.webBrowser1.Url.AbsoluteUri;
58 |
59 | if (WhenDocumentCompleted.GetInvocationList().Length > 0)
60 | {
61 | WhenDocumentCompleted(this.webBrowser1.DocumentTitle, this.webBrowser1.Url.AbsoluteUri);
62 | }
63 | }
64 |
65 | private void webBrowser1_NewWindow(string url, int fags, string targetFrameName, ref object postData, string headers, ref bool processed)
66 | {
67 | // Cancel popup.
68 | processed = true;
69 |
70 | if (WhenPopup.GetInvocationList().Length > 0)
71 | {
72 | WhenPopup(url);
73 | }
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/RemoteWebBrowser/TabBrowser.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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/RemoteWebBrowser/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeuroWhAI/RemoteWebBrowser/9368afc14946081505b21f9c1e2f6724eb685413/RemoteWebBrowser/icon.ico
--------------------------------------------------------------------------------
/RemoteWebBrowserClient/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/RemoteWebBrowserClient/BrowserService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Threading;
7 | using System.Net;
8 | using System.Net.Sockets;
9 | using System.IO;
10 | using System.Windows.Forms;
11 | using System.Drawing;
12 |
13 | namespace RemoteWebBrowserClient
14 | {
15 | public class BrowserService
16 | {
17 | public BrowserService()
18 | {
19 |
20 | }
21 |
22 | //###########################################################################################################################
23 |
24 | private TcpClient m_client = null;
25 | private Socket m_sock = null;
26 |
27 | public bool IsConnected
28 | {
29 | get
30 | {
31 | return (m_onService && m_client != null && this.ClientSocket.Connected);
32 | }
33 | }
34 |
35 | public Socket ClientSocket
36 | { get { return m_client.Client; } }
37 |
38 | private bool m_onService = true;
39 | private Thread m_service = null;
40 |
41 | public delegate void UpdateHandler(Image image);
42 | public event UpdateHandler WhenReceived;
43 |
44 | public bool AutoUpdate
45 | { get; set; } = true;
46 |
47 | //###########################################################################################################################
48 |
49 | public void Connect(string address, string port)
50 | {
51 | // 연결
52 | m_client = new TcpClient();
53 |
54 | try
55 | {
56 | m_client.Connect(address, int.Parse(port));
57 | m_sock = m_client.Client;
58 | }
59 | catch (SocketException)
60 | {
61 | m_client = null;
62 | m_sock = null;
63 | return;
64 | }
65 |
66 |
67 | m_onService = true;
68 |
69 | m_service = new Thread(DoService);
70 | m_service.Start();
71 | }
72 |
73 | public void Disconnect()
74 | {
75 | SendMessage("exit");
76 |
77 |
78 | m_onService = false;
79 |
80 |
81 | // 접속 해제
82 | if (m_client != null)
83 | {
84 | m_client.Close();
85 | m_client = null;
86 | }
87 |
88 | m_sock = null;
89 |
90 |
91 | if (m_service != null)
92 | {
93 | m_service.Join();
94 | m_service = null;
95 | }
96 | }
97 |
98 | //###########################################################################################################################
99 |
100 | private void DoService()
101 | {
102 | try
103 | {
104 | while (m_onService)
105 | {
106 | var intBytes = new byte[4];
107 |
108 | int recvResult = 0;
109 |
110 | try
111 | {
112 | recvResult = m_sock.Receive(intBytes, 0, intBytes.Length, SocketFlags.None);
113 | }
114 | catch (SocketException)
115 | {
116 | recvResult = -1;
117 | }
118 | #if !DEBUG
119 | catch
120 | {
121 | recvResult = -1;
122 | }
123 | #endif
124 |
125 | if (recvResult <= 0)
126 | {
127 | m_onService = false;
128 | return;
129 | }
130 |
131 | int bodySize = BitConverter.ToInt32(intBytes, 0);
132 |
133 | if (bodySize < 0)
134 | {
135 | m_onService = false;
136 | return;
137 | }
138 |
139 |
140 | const int BUFF_SIZE = 512;
141 | var buff = new byte[BUFF_SIZE];
142 | int received = 0;
143 |
144 | List totalBytes = new List();
145 |
146 | while (received < bodySize)
147 | {
148 | int blockSize = (bodySize - received >= BUFF_SIZE) ? BUFF_SIZE : bodySize - received;
149 |
150 | while (m_sock.Available < blockSize)
151 | {
152 | Thread.Sleep(1);
153 | }
154 |
155 | recvResult = m_sock.Receive(buff, 0, blockSize, SocketFlags.None);
156 |
157 | if (recvResult <= 0)
158 | {
159 | m_onService = false;
160 | return;
161 | }
162 |
163 | received += recvResult;
164 |
165 | totalBytes.AddRange(buff);
166 | }
167 |
168 |
169 | if (this.AutoUpdate)
170 | {
171 | UpdateImage();
172 | }
173 |
174 |
175 | Image image = null;
176 |
177 | using (var ms = new MemoryStream(totalBytes.ToArray()))
178 | {
179 | image = Image.FromStream(ms);
180 | }
181 |
182 |
183 | WhenReceived(image);
184 | }
185 | }
186 | #if DEBUG
187 | catch (Exception exp)
188 | {
189 | MessageBox.Show(exp.Message + "\n\n" + exp.StackTrace);
190 | }
191 | #else
192 | catch
193 | {
194 | // Ignore.
195 | }
196 | #endif
197 | }
198 |
199 | //###########################################################################################################################
200 |
201 | private void SendMessage(string cmd, string arg = null)
202 | {
203 | if (m_sock != null && m_sock.Connected)
204 | {
205 | string body = cmd;
206 |
207 | if (string.IsNullOrEmpty(arg) == false)
208 | {
209 | body += '|' + arg;
210 | }
211 |
212 |
213 | var bodyBytes = Encoding.UTF8.GetBytes(body);
214 |
215 | var intBytes = BitConverter.GetBytes(bodyBytes.Length);
216 | m_sock.Send(intBytes, 0, intBytes.Length, SocketFlags.None);
217 |
218 | m_sock.Send(bodyBytes, 0, bodyBytes.Length, SocketFlags.None);
219 | }
220 | }
221 |
222 | public void UpdateImage()
223 | {
224 | SendMessage("update");
225 | }
226 |
227 | public void SendMouseDown(int key, int x, int y)
228 | {
229 | SendMessage("mdown", key + "|" + x + "|" + y);
230 | }
231 |
232 | public void SendMouseUp(int key, int x, int y)
233 | {
234 | SendMessage("mup", key + "|" + x + "|" + y);
235 | }
236 |
237 | public void SendKeyDown(int key)
238 | {
239 | SendMessage("kdown", key.ToString());
240 | }
241 |
242 | public void SendKeyUp(int key)
243 | {
244 | SendMessage("kup", key.ToString());
245 | }
246 | }
247 | }
248 |
--------------------------------------------------------------------------------
/RemoteWebBrowserClient/Form_Main.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace RemoteWebBrowserClient
2 | {
3 | partial class Form_Main
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 Form 디자이너에서 생성한 코드
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(Form_Main));
33 | this.pictureBox_controller = new System.Windows.Forms.PictureBox();
34 | this.ToolStripMenuItem_file = new System.Windows.Forms.ToolStripMenuItem();
35 | this.ToolStripMenuItem_close = new System.Windows.Forms.ToolStripMenuItem();
36 | this.ToolStripMenuItem_connection = new System.Windows.Forms.ToolStripMenuItem();
37 | this.toolStripTextBox_ip = new System.Windows.Forms.ToolStripTextBox();
38 | this.toolStripTextBox_port = new System.Windows.Forms.ToolStripTextBox();
39 | this.ToolStripMenuItem_connect = new System.Windows.Forms.ToolStripMenuItem();
40 | this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
41 | this.ToolStripMenuItem_update = new System.Windows.Forms.ToolStripMenuItem();
42 | this.menuStrip_top = new System.Windows.Forms.MenuStrip();
43 | this.timer_check = new System.Windows.Forms.Timer(this.components);
44 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox_controller)).BeginInit();
45 | this.menuStrip_top.SuspendLayout();
46 | this.SuspendLayout();
47 | //
48 | // pictureBox_controller
49 | //
50 | this.pictureBox_controller.Location = new System.Drawing.Point(0, 27);
51 | this.pictureBox_controller.Name = "pictureBox_controller";
52 | this.pictureBox_controller.Size = new System.Drawing.Size(400, 400);
53 | this.pictureBox_controller.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
54 | this.pictureBox_controller.TabIndex = 0;
55 | this.pictureBox_controller.TabStop = false;
56 | this.pictureBox_controller.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox_controller_MouseDown);
57 | this.pictureBox_controller.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox_controller_MouseUp);
58 | //
59 | // ToolStripMenuItem_file
60 | //
61 | this.ToolStripMenuItem_file.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
62 | this.ToolStripMenuItem_close});
63 | this.ToolStripMenuItem_file.Name = "ToolStripMenuItem_file";
64 | this.ToolStripMenuItem_file.Size = new System.Drawing.Size(43, 20);
65 | this.ToolStripMenuItem_file.Text = "파일";
66 | //
67 | // ToolStripMenuItem_close
68 | //
69 | this.ToolStripMenuItem_close.Name = "ToolStripMenuItem_close";
70 | this.ToolStripMenuItem_close.Size = new System.Drawing.Size(98, 22);
71 | this.ToolStripMenuItem_close.Text = "종료";
72 | this.ToolStripMenuItem_close.Click += new System.EventHandler(this.ToolStripMenuItem_close_Click);
73 | //
74 | // ToolStripMenuItem_connection
75 | //
76 | this.ToolStripMenuItem_connection.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
77 | this.toolStripTextBox_ip,
78 | this.toolStripTextBox_port,
79 | this.ToolStripMenuItem_connect,
80 | this.toolStripSeparator1,
81 | this.ToolStripMenuItem_update});
82 | this.ToolStripMenuItem_connection.Name = "ToolStripMenuItem_connection";
83 | this.ToolStripMenuItem_connection.Size = new System.Drawing.Size(43, 20);
84 | this.ToolStripMenuItem_connection.Text = "연결";
85 | //
86 | // toolStripTextBox_ip
87 | //
88 | this.toolStripTextBox_ip.Name = "toolStripTextBox_ip";
89 | this.toolStripTextBox_ip.Size = new System.Drawing.Size(100, 23);
90 | this.toolStripTextBox_ip.Text = "Server IP";
91 | //
92 | // toolStripTextBox_port
93 | //
94 | this.toolStripTextBox_port.Name = "toolStripTextBox_port";
95 | this.toolStripTextBox_port.Size = new System.Drawing.Size(100, 23);
96 | this.toolStripTextBox_port.Text = "Server Port";
97 | //
98 | // ToolStripMenuItem_connect
99 | //
100 | this.ToolStripMenuItem_connect.Name = "ToolStripMenuItem_connect";
101 | this.ToolStripMenuItem_connect.Size = new System.Drawing.Size(160, 22);
102 | this.ToolStripMenuItem_connect.Text = "Connect";
103 | this.ToolStripMenuItem_connect.Click += new System.EventHandler(this.ToolStripMenuItem_connect_Click);
104 | //
105 | // toolStripSeparator1
106 | //
107 | this.toolStripSeparator1.Name = "toolStripSeparator1";
108 | this.toolStripSeparator1.Size = new System.Drawing.Size(157, 6);
109 | //
110 | // ToolStripMenuItem_update
111 | //
112 | this.ToolStripMenuItem_update.Checked = true;
113 | this.ToolStripMenuItem_update.CheckState = System.Windows.Forms.CheckState.Checked;
114 | this.ToolStripMenuItem_update.Name = "ToolStripMenuItem_update";
115 | this.ToolStripMenuItem_update.Size = new System.Drawing.Size(160, 22);
116 | this.ToolStripMenuItem_update.Text = "Auto Update";
117 | this.ToolStripMenuItem_update.Click += new System.EventHandler(this.ToolStripMenuItem_update_Click);
118 | //
119 | // menuStrip_top
120 | //
121 | this.menuStrip_top.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
122 | this.ToolStripMenuItem_file,
123 | this.ToolStripMenuItem_connection});
124 | this.menuStrip_top.Location = new System.Drawing.Point(0, 0);
125 | this.menuStrip_top.Name = "menuStrip_top";
126 | this.menuStrip_top.Size = new System.Drawing.Size(784, 24);
127 | this.menuStrip_top.TabIndex = 1;
128 | this.menuStrip_top.Text = "menuStrip1";
129 | //
130 | // timer_check
131 | //
132 | this.timer_check.Interval = 2000;
133 | this.timer_check.Tick += new System.EventHandler(this.timer_check_Tick);
134 | //
135 | // Form_Main
136 | //
137 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
138 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
139 | this.AutoSize = true;
140 | this.ClientSize = new System.Drawing.Size(784, 561);
141 | this.Controls.Add(this.pictureBox_controller);
142 | this.Controls.Add(this.menuStrip_top);
143 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
144 | this.KeyPreview = true;
145 | this.MainMenuStrip = this.menuStrip_top;
146 | this.Name = "Form_Main";
147 | this.Text = "Remote Web Browser";
148 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form_Main_FormClosing);
149 | this.Load += new System.EventHandler(this.Form_Main_Load);
150 | this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form_Main_KeyDown);
151 | this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form_Main_KeyUp);
152 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox_controller)).EndInit();
153 | this.menuStrip_top.ResumeLayout(false);
154 | this.menuStrip_top.PerformLayout();
155 | this.ResumeLayout(false);
156 | this.PerformLayout();
157 |
158 | }
159 |
160 | #endregion
161 |
162 | private System.Windows.Forms.PictureBox pictureBox_controller;
163 | private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_file;
164 | private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_close;
165 | private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_connection;
166 | private System.Windows.Forms.ToolStripTextBox toolStripTextBox_ip;
167 | private System.Windows.Forms.MenuStrip menuStrip_top;
168 | private System.Windows.Forms.ToolStripTextBox toolStripTextBox_port;
169 | private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_connect;
170 | private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
171 | private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_update;
172 | private System.Windows.Forms.Timer timer_check;
173 | }
174 | }
175 |
176 |
--------------------------------------------------------------------------------
/RemoteWebBrowserClient/Form_Main.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Forms;
10 |
11 | namespace RemoteWebBrowserClient
12 | {
13 | public partial class Form_Main : Form
14 | {
15 | public Form_Main()
16 | {
17 | InitializeComponent();
18 |
19 |
20 | m_client.WhenReceived += (Image image) =>
21 | {
22 | this.pictureBox_controller.Invoke(new Action(() => this.pictureBox_controller.Image = image));
23 | };
24 |
25 |
26 | #if DEBUG
27 | this.toolStripTextBox_ip.Text = "127.0.0.1";
28 | this.toolStripTextBox_port.Text = "42212";
29 | #endif
30 | }
31 |
32 | //###########################################################################################################################
33 |
34 | private BrowserService m_client = new BrowserService();
35 |
36 | //###########################################################################################################################
37 |
38 | private void Form_Main_Load(object sender, EventArgs e)
39 | {
40 | this.ToolStripMenuItem_update.Checked = m_client.AutoUpdate;
41 | }
42 |
43 | private void Form_Main_FormClosing(object sender, FormClosingEventArgs e)
44 | {
45 | m_client.Disconnect();
46 | }
47 |
48 | private void ToolStripMenuItem_close_Click(object sender, EventArgs e)
49 | {
50 | Application.Exit();
51 | }
52 |
53 | private void ToolStripMenuItem_connect_Click(object sender, EventArgs e)
54 | {
55 | m_client.Connect(this.toolStripTextBox_ip.Text, this.toolStripTextBox_port.Text);
56 |
57 | if (m_client.IsConnected)
58 | {
59 | this.ToolStripMenuItem_update.Enabled = true;
60 | this.ToolStripMenuItem_connect.Enabled = false;
61 |
62 | this.timer_check.Start();
63 | }
64 | else
65 | {
66 | MessageBox.Show("연결할 수 없습니다!", "Error!",
67 | MessageBoxButtons.OK, MessageBoxIcon.Warning);
68 | }
69 | }
70 |
71 | private void ToolStripMenuItem_update_Click(object sender, EventArgs e)
72 | {
73 | this.ToolStripMenuItem_update.Checked = !this.ToolStripMenuItem_update.Checked;
74 |
75 | m_client.AutoUpdate = this.ToolStripMenuItem_update.Checked;
76 |
77 | if (m_client.AutoUpdate)
78 | {
79 | m_client.UpdateImage();
80 | }
81 | }
82 |
83 | private void timer_check_Tick(object sender, EventArgs e)
84 | {
85 | if (m_client.IsConnected == false)
86 | {
87 | this.timer_check.Stop();
88 |
89 | MessageBox.Show("서버와의 연결이 끊어졌습니다!", "Error!",
90 | MessageBoxButtons.OK, MessageBoxIcon.Error);
91 |
92 | Application.Exit();
93 | }
94 | }
95 |
96 | //###########################################################################################################################
97 |
98 | private void pictureBox_controller_MouseDown(object sender, MouseEventArgs e)
99 | {
100 | m_client.SendMouseDown((int)e.Button, e.X, e.Y);
101 | }
102 |
103 | private void pictureBox_controller_MouseUp(object sender, MouseEventArgs e)
104 | {
105 | m_client.SendMouseUp((int)e.Button, e.X, e.Y);
106 | }
107 |
108 | private void Form_Main_KeyDown(object sender, KeyEventArgs e)
109 | {
110 | m_client.SendKeyDown(e.KeyValue);
111 | }
112 |
113 | private void Form_Main_KeyUp(object sender, KeyEventArgs e)
114 | {
115 | m_client.SendKeyUp(e.KeyValue);
116 | }
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/RemoteWebBrowserClient/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using System.Windows.Forms;
6 |
7 | namespace RemoteWebBrowserClient
8 | {
9 | static class Program
10 | {
11 | ///
12 | /// 해당 응용 프로그램의 주 진입점입니다.
13 | ///
14 | [STAThread]
15 | static void Main()
16 | {
17 | Application.EnableVisualStyles();
18 | Application.SetCompatibleTextRenderingDefault(false);
19 | Application.Run(new Form_Main());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/RemoteWebBrowserClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해
6 | // 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
7 | // 이러한 특성 값을 변경하세요.
8 | [assembly: AssemblyTitle("RemoteWebBrowserClient")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("RemoteWebBrowserClient")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
18 | // 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
19 | // 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
20 | [assembly: ComVisible(false)]
21 |
22 | // 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
23 | [assembly: Guid("0e2ee8b8-cea1-45c9-bc97-a35fb87faa9b")]
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 |
--------------------------------------------------------------------------------
/RemoteWebBrowserClient/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 이 코드는 도구를 사용하여 생성되었습니다.
4 | // 런타임 버전:4.0.30319.42000
5 | //
6 | // 파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면
7 | // 이러한 변경 내용이 손실됩니다.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace RemoteWebBrowserClient.Properties
12 | {
13 |
14 |
15 | ///
16 | /// 지역화된 문자열 등을 찾기 위한 강력한 형식의 리소스 클래스입니다.
17 | ///
18 | // 이 클래스는 ResGen 또는 Visual Studio와 같은 도구를 통해 StronglyTypedResourceBuilder
19 | // 클래스에서 자동으로 생성되었습니다.
20 | // 멤버를 추가하거나 제거하려면 .ResX 파일을 편집한 다음 /str 옵션을 사용하여
21 | // ResGen을 다시 실행하거나 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 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// 이 클래스에서 사용하는 캐시된 ResourceManager 인스턴스를 반환합니다.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("RemoteWebBrowserClient.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// 이 강력한 형식의 리소스 클래스를 사용하여 모든 리소스 조회에 대해
56 | /// 현재 스레드의 CurrentUICulture 속성을 재정의합니다.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/RemoteWebBrowserClient/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 |
--------------------------------------------------------------------------------
/RemoteWebBrowserClient/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
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 RemoteWebBrowserClient.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 |
--------------------------------------------------------------------------------
/RemoteWebBrowserClient/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/RemoteWebBrowserClient/RemoteWebBrowserClient.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {0E2EE8B8-CEA1-45C9-BC97-A35FB87FAA9B}
8 | WinExe
9 | RemoteWebBrowserClient
10 | RemoteWebBrowserClient
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 | icon.ico
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | Form
54 |
55 |
56 | Form_Main.cs
57 |
58 |
59 |
60 |
61 | Form_Main.cs
62 |
63 |
64 | ResXFileCodeGenerator
65 | Resources.Designer.cs
66 | Designer
67 |
68 |
69 | True
70 | Resources.resx
71 |
72 |
73 | SettingsSingleFileGenerator
74 | Settings.Designer.cs
75 |
76 |
77 | True
78 | Settings.settings
79 | True
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/RemoteWebBrowserClient/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeuroWhAI/RemoteWebBrowser/9368afc14946081505b21f9c1e2f6724eb685413/RemoteWebBrowserClient/icon.ico
--------------------------------------------------------------------------------
/RemoteWebBrowserServer/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/RemoteWebBrowserServer/BrowserService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Threading;
7 | using System.Diagnostics;
8 | using System.Windows.Forms;
9 | using System.IO;
10 | using System.Net;
11 | using System.Net.Sockets;
12 | using System.Drawing;
13 | using System.Drawing.Imaging;
14 |
15 | namespace RemoteWebBrowserServer
16 | {
17 | public class BrowserService
18 | {
19 | public BrowserService(TcpClient client)
20 | {
21 | m_sock = client.Client;
22 | }
23 |
24 | //###########################################################################################################################
25 |
26 | private Socket m_sock;
27 |
28 | public bool IsConnected
29 | {
30 | get
31 | {
32 | return (m_sock.Connected && m_browser != null && m_browser.HasExited == false);
33 | }
34 | }
35 |
36 | public IntPtr SocketHandle
37 | { get { return m_sock.Handle; } }
38 |
39 | private Process m_browser = null;
40 | private Thread m_service = null;
41 |
42 | public IntPtr BrowserHandle
43 | { get { return m_browser.MainWindowHandle; } }
44 |
45 | //###########################################################################################################################
46 |
47 | public void Start()
48 | {
49 | #if DEBUG
50 | var info = new ProcessStartInfo(Application.StartupPath + "/../../../RemoteWebBrowser/bin/Debug/RemoteWebBrowser.exe")
51 | #else
52 | var info = new ProcessStartInfo(Application.StartupPath + "/RemoteWebBrowser.exe")
53 | #endif
54 | {
55 | ErrorDialog = false,
56 | WindowStyle = ProcessWindowStyle.Normal,
57 | };
58 |
59 | m_browser = Process.Start(info);
60 |
61 |
62 | m_service = new Thread(DoService);
63 | m_service.Start();
64 | }
65 |
66 | public void Stop()
67 | {
68 | if (m_sock != null && m_sock.Connected)
69 | {
70 | var intBytes = BitConverter.GetBytes((int)-1);
71 |
72 | m_sock.Send(intBytes, 0, intBytes.Length, SocketFlags.None);
73 |
74 | m_sock.Close();
75 | }
76 |
77 |
78 | if (m_browser != null && m_browser.HasExited == false)
79 | {
80 | m_browser.CloseMainWindow();
81 | m_browser.WaitForExit();
82 | }
83 |
84 | if (m_service != null)
85 | {
86 | m_service.Join();
87 | m_service = null;
88 | }
89 | }
90 |
91 | //###########################################################################################################################
92 |
93 | private void DoService()
94 | {
95 | try
96 | {
97 | m_browser.WaitForInputIdle();
98 |
99 |
100 | Thread.Sleep(1000);
101 |
102 |
103 | SendImage();
104 |
105 |
106 | while (m_browser.HasExited == false)
107 | {
108 | var packet = new Packet();
109 | packet.Read(m_sock);
110 |
111 |
112 | if (packet.Command == "exit")
113 | {
114 | m_browser.CloseMainWindow();
115 | }
116 | else if (packet.Command == "update")
117 | {
118 | SendImage();
119 | }
120 | else if (packet.Command == "mdown")
121 | {
122 | WinApi.SendMouseDown(this.BrowserHandle, (MouseButtons)int.Parse(packet.Messages[1]),
123 | new Point(int.Parse(packet.Messages[2]), int.Parse(packet.Messages[3])));
124 | }
125 | else if (packet.Command == "mup")
126 | {
127 | WinApi.SendMouseUp(this.BrowserHandle, (MouseButtons)int.Parse(packet.Messages[1]),
128 | new Point(int.Parse(packet.Messages[2]), int.Parse(packet.Messages[3])));
129 | }
130 | else if (packet.Command == "kdown")
131 | {
132 | WinApi.keybd_event(int.Parse(packet.Messages[1]), 0, 0, 0);
133 | }
134 | else if (packet.Command == "kup")
135 | {
136 | WinApi.keybd_event(int.Parse(packet.Messages[1]), 0, 2, 0);
137 | }
138 | }
139 |
140 |
141 | m_browser.Dispose();
142 | m_browser = null;
143 | }
144 | #if DEBUG
145 | catch (Exception exp)
146 | {
147 | MessageBox.Show(exp.Message + "\n\n" + exp.StackTrace);
148 | }
149 | #else
150 | catch
151 | {
152 | // Ignore.
153 | }
154 | #endif
155 | }
156 |
157 | //###########################################################################################################################
158 |
159 | private void SendImage()
160 | {
161 | var image = WinApi.CaptureWindow(this.BrowserHandle);
162 |
163 | byte[] imgBytes = null;
164 |
165 | using (var ms = new MemoryStream())
166 | {
167 | image.Save(ms, ImageFormat.Jpeg);
168 |
169 | imgBytes = ms.GetBuffer();
170 | }
171 |
172 |
173 | var intBytes = BitConverter.GetBytes(imgBytes.Length);
174 |
175 | m_sock.Send(intBytes, 0, intBytes.Length, SocketFlags.None);
176 |
177 |
178 | const int BUFF_SIZE = 512;
179 | int end = imgBytes.Length;
180 | int start = 0;
181 |
182 | while (start < end)
183 | {
184 | int n = (end - start >= BUFF_SIZE) ? BUFF_SIZE : end - start;
185 |
186 | m_sock.Send(imgBytes, start, n, SocketFlags.None);
187 |
188 | start += n;
189 | }
190 | }
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/RemoteWebBrowserServer/Form_Main.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace RemoteWebBrowserServer
2 | {
3 | partial class Form_Main
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 Form 디자이너에서 생성한 코드
24 |
25 | ///
26 | /// 디자이너 지원에 필요한 메서드입니다.
27 | /// 이 메서드의 내용을 코드 편집기로 수정하지 마세요.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form_Main));
32 | this.textBox_port = new System.Windows.Forms.TextBox();
33 | this.button_start = new System.Windows.Forms.Button();
34 | this.label1 = new System.Windows.Forms.Label();
35 | this.listBox_log = new System.Windows.Forms.ListBox();
36 | this.label2 = new System.Windows.Forms.Label();
37 | this.SuspendLayout();
38 | //
39 | // textBox_port
40 | //
41 | this.textBox_port.Location = new System.Drawing.Point(53, 6);
42 | this.textBox_port.Name = "textBox_port";
43 | this.textBox_port.Size = new System.Drawing.Size(159, 21);
44 | this.textBox_port.TabIndex = 0;
45 | this.textBox_port.Text = "42212";
46 | //
47 | // button_start
48 | //
49 | this.button_start.Location = new System.Drawing.Point(218, 4);
50 | this.button_start.Name = "button_start";
51 | this.button_start.Size = new System.Drawing.Size(75, 23);
52 | this.button_start.TabIndex = 1;
53 | this.button_start.Text = "Start";
54 | this.button_start.UseVisualStyleBackColor = true;
55 | this.button_start.Click += new System.EventHandler(this.button_start_Click);
56 | //
57 | // label1
58 | //
59 | this.label1.AutoSize = true;
60 | this.label1.Location = new System.Drawing.Point(12, 9);
61 | this.label1.Name = "label1";
62 | this.label1.Size = new System.Drawing.Size(35, 12);
63 | this.label1.TabIndex = 2;
64 | this.label1.Text = "Port :";
65 | //
66 | // listBox_log
67 | //
68 | this.listBox_log.FormattingEnabled = true;
69 | this.listBox_log.ItemHeight = 12;
70 | this.listBox_log.Location = new System.Drawing.Point(12, 54);
71 | this.listBox_log.Name = "listBox_log";
72 | this.listBox_log.Size = new System.Drawing.Size(454, 256);
73 | this.listBox_log.TabIndex = 3;
74 | //
75 | // label2
76 | //
77 | this.label2.AutoSize = true;
78 | this.label2.Location = new System.Drawing.Point(12, 39);
79 | this.label2.Name = "label2";
80 | this.label2.Size = new System.Drawing.Size(26, 12);
81 | this.label2.TabIndex = 4;
82 | this.label2.Text = "Log";
83 | //
84 | // Form_Main
85 | //
86 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
87 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
88 | this.ClientSize = new System.Drawing.Size(478, 319);
89 | this.Controls.Add(this.label2);
90 | this.Controls.Add(this.listBox_log);
91 | this.Controls.Add(this.label1);
92 | this.Controls.Add(this.button_start);
93 | this.Controls.Add(this.textBox_port);
94 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
95 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
96 | this.MaximizeBox = false;
97 | this.Name = "Form_Main";
98 | this.Text = "Remote Web Browser Server";
99 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form_Main_FormClosing);
100 | this.Load += new System.EventHandler(this.Form_Main_Load);
101 | this.ResumeLayout(false);
102 | this.PerformLayout();
103 |
104 | }
105 |
106 | #endregion
107 |
108 | private System.Windows.Forms.TextBox textBox_port;
109 | private System.Windows.Forms.Button button_start;
110 | private System.Windows.Forms.Label label1;
111 | private System.Windows.Forms.ListBox listBox_log;
112 | private System.Windows.Forms.Label label2;
113 | }
114 | }
115 |
116 |
--------------------------------------------------------------------------------
/RemoteWebBrowserServer/Form_Main.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Threading;
10 | using System.Windows.Forms;
11 | using System.Net;
12 | using System.Net.Sockets;
13 |
14 | namespace RemoteWebBrowserServer
15 | {
16 | public partial class Form_Main : Form
17 | {
18 | public Form_Main()
19 | {
20 | InitializeComponent();
21 | }
22 |
23 | //###########################################################################################################################
24 |
25 | private bool m_acceptRun = true;
26 | private Thread m_listenerService = null;
27 | private TcpListener m_listener = null;
28 |
29 | private List m_clients = new List();
30 |
31 | //###########################################################################################################################
32 |
33 | private void Log(string message)
34 | {
35 | this.listBox_log.Invoke(new Action(() =>
36 | {
37 | this.listBox_log.Items.Add(message);
38 | this.listBox_log.SelectedIndex = this.listBox_log.Items.Count - 1;
39 | }));
40 | }
41 |
42 | //###########################################################################################################################
43 |
44 | private void Form_Main_Load(object sender, EventArgs e)
45 | {
46 | Start();
47 | }
48 |
49 | private void Form_Main_FormClosing(object sender, FormClosingEventArgs e)
50 | {
51 | Stop();
52 | }
53 |
54 | private void button_start_Click(object sender, EventArgs e)
55 | {
56 | if (this.button_start.Text == "Stop")
57 | {
58 | Stop();
59 | }
60 | else
61 | {
62 | Start();
63 | }
64 | }
65 |
66 | //###########################################################################################################################
67 |
68 | private void Start()
69 | {
70 | Log("Start Server.");
71 |
72 |
73 | this.textBox_port.Enabled = false;
74 | this.button_start.Text = "Stop";
75 |
76 |
77 | m_acceptRun = true;
78 |
79 |
80 | m_listener = new TcpListener(IPAddress.Any, int.Parse(this.textBox_port.Text));
81 | m_listener.Start();
82 |
83 |
84 | m_listenerService = new Thread(Listen);
85 | m_listenerService.Start();
86 | }
87 |
88 | private void Stop()
89 | {
90 | m_acceptRun = false;
91 |
92 |
93 | if (m_listenerService != null)
94 | {
95 | m_listenerService.Join();
96 | m_listenerService = null;
97 | }
98 |
99 |
100 | if (m_listener != null)
101 | {
102 | m_listener.Stop();
103 | m_listener = null;
104 | }
105 |
106 |
107 | foreach (var browser in m_clients)
108 | {
109 | browser.Stop();
110 | }
111 | m_clients.Clear();
112 |
113 |
114 | this.textBox_port.Enabled = true;
115 | this.button_start.Text = "Start";
116 |
117 |
118 | Log("Stop Server.");
119 | }
120 |
121 | private void Listen()
122 | {
123 | Log("Start listening.");
124 |
125 |
126 | while (m_acceptRun)
127 | {
128 | // 보류중인 접속이 없으면 대기
129 | while (!m_listener.Pending())
130 | {
131 | if (m_acceptRun == false)
132 | return;
133 |
134 |
135 | // 연결 확인
136 | for (int i = 0; i < m_clients.Count; ++i)
137 | {
138 | var client = m_clients[i];
139 |
140 | if (client.IsConnected == false)
141 | {
142 | Log("Disconnect " + client.SocketHandle + " socket.");
143 |
144 | client.Stop();
145 |
146 | m_clients.RemoveAt(i);
147 | --i;
148 | }
149 | }
150 |
151 |
152 | Thread.Sleep(128);
153 | }
154 |
155 |
156 | // 접속확인
157 | var newClient = m_listener.AcceptTcpClient();
158 |
159 | // 클라이언트 생성
160 | if (newClient != null)
161 | {
162 | Log("Connect " + newClient.Client.Handle + " socket.");
163 |
164 |
165 | var browser = new BrowserService(newClient);
166 | browser.Start();
167 |
168 | m_clients.Add(browser);
169 | }
170 | }
171 | }
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/RemoteWebBrowserServer/Packet.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.IO;
7 | using System.Net.Sockets;
8 | using System.Threading;
9 |
10 | namespace RemoteWebBrowserServer
11 | {
12 | public class Packet
13 | {
14 | public Packet()
15 | {
16 |
17 | }
18 |
19 | //###########################################################################################################################
20 |
21 | public string[] Messages
22 | { get; set; }
23 |
24 | public string Command
25 | { get { return this.Messages[0]; } }
26 |
27 | //###########################################################################################################################
28 |
29 | public void Read(Socket sock)
30 | {
31 | var intBytes = new byte[4];
32 |
33 | int recvResult = 0;
34 |
35 | try
36 | {
37 | recvResult = sock.Receive(intBytes, 0, intBytes.Length, SocketFlags.None);
38 | }
39 | catch (SocketException)
40 | {
41 | recvResult = -1;
42 | }
43 | #if !DEBUG
44 | catch
45 | {
46 | recvResult = -1;
47 | }
48 | #endif
49 |
50 | if (recvResult <= 0)
51 | {
52 | Messages = new[] { "exit" };
53 | return;
54 | }
55 |
56 | int bodySize = BitConverter.ToInt32(intBytes, 0);
57 |
58 |
59 | var bodyBytes = new byte[bodySize];
60 |
61 | while (sock.Available < bodySize)
62 | {
63 | Thread.Sleep(1);
64 | }
65 |
66 | sock.Receive(bodyBytes, 0, bodyBytes.Length, SocketFlags.None);
67 |
68 | this.Messages = Encoding.UTF8.GetString(bodyBytes).Split('|');
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/RemoteWebBrowserServer/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using System.Windows.Forms;
6 | using System.IO;
7 |
8 | namespace RemoteWebBrowserServer
9 | {
10 | static class Program
11 | {
12 | ///
13 | /// 해당 응용 프로그램의 주 진입점입니다.
14 | ///
15 | [STAThread]
16 | static void Main()
17 | {
18 | Directory.SetCurrentDirectory(Application.StartupPath);
19 |
20 |
21 | Application.EnableVisualStyles();
22 | Application.SetCompatibleTextRenderingDefault(false);
23 | Application.Run(new Form_Main());
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/RemoteWebBrowserServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해
6 | // 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
7 | // 이러한 특성 값을 변경하세요.
8 | [assembly: AssemblyTitle("RemoteWebBrowserServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("RemoteWebBrowserServer")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
18 | // 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
19 | // 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
20 | [assembly: ComVisible(false)]
21 |
22 | // 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
23 | [assembly: Guid("2d7da974-14fb-4f9a-9c16-15022579135c")]
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 |
--------------------------------------------------------------------------------
/RemoteWebBrowserServer/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 이 코드는 도구를 사용하여 생성되었습니다.
4 | // 런타임 버전:4.0.30319.42000
5 | //
6 | // 파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면
7 | // 이러한 변경 내용이 손실됩니다.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace RemoteWebBrowserServer.Properties
12 | {
13 |
14 |
15 | ///
16 | /// 지역화된 문자열 등을 찾기 위한 강력한 형식의 리소스 클래스입니다.
17 | ///
18 | // 이 클래스는 ResGen 또는 Visual Studio와 같은 도구를 통해 StronglyTypedResourceBuilder
19 | // 클래스에서 자동으로 생성되었습니다.
20 | // 멤버를 추가하거나 제거하려면 .ResX 파일을 편집한 다음 /str 옵션을 사용하여
21 | // ResGen을 다시 실행하거나 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 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// 이 클래스에서 사용하는 캐시된 ResourceManager 인스턴스를 반환합니다.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("RemoteWebBrowserServer.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// 이 강력한 형식의 리소스 클래스를 사용하여 모든 리소스 조회에 대해
56 | /// 현재 스레드의 CurrentUICulture 속성을 재정의합니다.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/RemoteWebBrowserServer/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 |
--------------------------------------------------------------------------------
/RemoteWebBrowserServer/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
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 RemoteWebBrowserServer.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 |
--------------------------------------------------------------------------------
/RemoteWebBrowserServer/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/RemoteWebBrowserServer/RemoteWebBrowserServer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {2D7DA974-14FB-4F9A-9C16-15022579135C}
8 | WinExe
9 | RemoteWebBrowserServer
10 | RemoteWebBrowserServer
11 | v4.5.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 | icon.ico
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | Form
54 |
55 |
56 | Form_Main.cs
57 |
58 |
59 |
60 |
61 |
62 |
63 | Form_Main.cs
64 |
65 |
66 | ResXFileCodeGenerator
67 | Resources.Designer.cs
68 | Designer
69 |
70 |
71 | True
72 | Resources.resx
73 |
74 |
75 | SettingsSingleFileGenerator
76 | Settings.Designer.cs
77 |
78 |
79 | True
80 | Settings.settings
81 | True
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/RemoteWebBrowserServer/WinApi.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows.Forms;
7 | using System.Runtime.InteropServices;
8 | using System.Drawing;
9 |
10 | namespace RemoteWebBrowserServer
11 | {
12 | public static class WinApi
13 | {
14 | [DllImport("gdi32.dll")]
15 | public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hObjectSource, int nXSrc, int nYSrc, int dwRop);
16 | [DllImport("gdi32.dll")]
17 | public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int nWidth, int nHeight);
18 | [DllImport("gdi32.dll")]
19 | public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
20 | [DllImport("gdi32.dll")]
21 | public static extern bool DeleteDC(IntPtr hDC);
22 | [DllImport("gdi32.dll")]
23 | public static extern bool DeleteObject(IntPtr hObject);
24 | [DllImport("gdi32.dll")]
25 | public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
26 |
27 | [DllImport("user32.dll")]
28 | public static extern IntPtr GetDesktopWindow();
29 | [DllImport("user32.dll")]
30 | public static extern IntPtr GetWindowDC(IntPtr hWnd);
31 | [DllImport("user32.dll")]
32 | public static extern IntPtr GetWindowRect(IntPtr hWnd, ref RECT rect);
33 | [DllImport("user32.dll")]
34 | public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
35 |
36 | public const int SRCCOPY = 13369376;
37 |
38 | [StructLayout(LayoutKind.Sequential)]
39 | public struct RECT
40 | {
41 | public int left;
42 | public int top;
43 | public int right;
44 | public int bottom;
45 | }
46 |
47 | public static Image CaptureWindow(IntPtr handle)
48 | {
49 | try
50 | {
51 | IntPtr hdcSrc = GetWindowDC(handle);
52 |
53 | RECT clientRect = new RECT();
54 | GetClientRect(handle, ref clientRect);
55 |
56 | RECT windowRect = new RECT();
57 | GetWindowRect(handle, ref windowRect);
58 |
59 | int width = clientRect.right - clientRect.left;
60 | int height = clientRect.bottom - clientRect.top;
61 |
62 | IntPtr hdcDest = CreateCompatibleDC(hdcSrc);
63 | IntPtr hBitmap = CreateCompatibleBitmap(hdcSrc, width, height);
64 |
65 | IntPtr hOld = SelectObject(hdcDest, hBitmap);
66 | BitBlt(hdcDest, 0, 0, width, height, hdcSrc,
67 | (windowRect.right - windowRect.left - width) / 2,
68 | (windowRect.bottom - windowRect.top - height) - (windowRect.right - windowRect.left - width) / 2,
69 | SRCCOPY);
70 | SelectObject(hdcDest, hOld);
71 | DeleteDC(hdcDest);
72 | ReleaseDC(handle, hdcSrc);
73 |
74 | Image image = Image.FromHbitmap(hBitmap);
75 | DeleteObject(hBitmap);
76 |
77 | return image;
78 | }
79 | #if DEBUG
80 | catch (Exception exp)
81 | {
82 | MessageBox.Show(exp.Message + "\n\n" + exp.StackTrace);
83 | }
84 | #else
85 | catch
86 | {
87 | // Ignore.
88 | }
89 | #endif
90 |
91 | return Icon.FromHandle(handle).ToBitmap();
92 | }
93 |
94 | [DllImport("user32.dll")]
95 | static extern bool GetClientRect(IntPtr hWnd, ref RECT lpRect);
96 |
97 | [DllImport("user32.dll")]
98 | static extern bool ClientToScreen(IntPtr hWnd, ref Point lpPoint);
99 |
100 | [DllImport("user32.dll")]
101 | internal static extern uint SendInput(uint nInputs, [MarshalAs(UnmanagedType.LPArray), In] INPUT[] pInputs, int cbSize);
102 |
103 | internal struct INPUT
104 | {
105 | public UInt32 Type;
106 | public MOUSEKEYBDHARDWAREINPUT Data;
107 | }
108 |
109 | [StructLayout(LayoutKind.Explicit)]
110 | internal struct MOUSEKEYBDHARDWAREINPUT
111 | {
112 | [FieldOffset(0)]
113 | public MOUSEINPUT Mouse;
114 | }
115 |
116 | internal struct MOUSEINPUT
117 | {
118 | public Int32 X;
119 | public Int32 Y;
120 | public UInt32 MouseData;
121 | public UInt32 Flags;
122 | public UInt32 Time;
123 | public IntPtr ExtraInfo;
124 | }
125 |
126 | private const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
127 | private const uint MOUSEEVENTF_LEFTUP = 0x0004;
128 | private const uint MOUSEEVENTF_RIGHTDOWN = 0x0008;
129 | private const uint MOUSEEVENTF_RIGHTUP = 0x0010;
130 | private const uint MOUSEEVENTF_MIDDLEDOWN = 0x0020;
131 | private const uint MOUSEEVENTF_MIDDLEUP = 0x0040;
132 |
133 | public struct POINT
134 | {
135 | public Int32 x;
136 | public Int32 y;
137 | }
138 |
139 | [DllImport("user32")]
140 | private static extern Int32 GetCursorPos(out POINT pt);
141 |
142 | public static Point GetCursorPosition()
143 | {
144 | POINT pt;
145 | GetCursorPos(out pt);
146 |
147 | return new Point(pt.x, pt.y);
148 | }
149 |
150 | [DllImport("user32.dll")]
151 | [return: MarshalAs(UnmanagedType.Bool)]
152 | public static extern bool SetCursorPos(int x, int y);
153 |
154 | private static uint MouseButtonToCode(MouseButtons key)
155 | {
156 | switch (key)
157 | {
158 | case MouseButtons.Left:
159 | return MOUSEEVENTF_LEFTDOWN;
160 | case MouseButtons.Right:
161 | return MOUSEEVENTF_RIGHTDOWN;
162 | case MouseButtons.Middle:
163 | return MOUSEEVENTF_MIDDLEDOWN;
164 | }
165 |
166 | return 0u;
167 | }
168 |
169 | public static void SendMouseDown(IntPtr wndHandle, MouseButtons key, Point clientPoint)
170 | {
171 | var oldPos = GetCursorPosition();
172 |
173 | /// get screen coordinates
174 | ClientToScreen(wndHandle, ref clientPoint);
175 |
176 | /// set cursor on coords, and press mouse
177 | SetCursorPos(clientPoint.X, clientPoint.Y);
178 |
179 | var inputMouseDown = new INPUT();
180 | inputMouseDown.Type = 0; /// input type mouse
181 | inputMouseDown.Data.Mouse.Flags = MouseButtonToCode(key);
182 |
183 | var inputs = new INPUT[] { inputMouseDown };
184 | SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
185 |
186 | /// return mouse
187 | SetCursorPos(oldPos.X, oldPos.Y);
188 | }
189 |
190 | public static void SendMouseUp(IntPtr wndHandle, MouseButtons key, Point clientPoint)
191 | {
192 | var oldPos = GetCursorPosition();
193 |
194 | /// get screen coordinates
195 | ClientToScreen(wndHandle, ref clientPoint);
196 |
197 | /// set cursor on coords, and press mouse
198 | SetCursorPos(clientPoint.X, clientPoint.Y);
199 |
200 | var inputMouseUp = new INPUT();
201 | inputMouseUp.Type = 0; /// input type mouse
202 | inputMouseUp.Data.Mouse.Flags = (MouseButtonToCode(key) << 1);
203 |
204 | var inputs = new INPUT[] { inputMouseUp };
205 | SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
206 |
207 | /// return mouse
208 | SetCursorPos(oldPos.X, oldPos.Y);
209 | }
210 |
211 | [DllImport("user32.dll")]
212 | public static extern void keybd_event(int vk, uint scan, uint flags, uint extraInfo);
213 | }
214 | }
215 |
--------------------------------------------------------------------------------
/RemoteWebBrowserServer/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeuroWhAI/RemoteWebBrowser/9368afc14946081505b21f9c1e2f6724eb685413/RemoteWebBrowserServer/icon.ico
--------------------------------------------------------------------------------
/Resources/demo.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeuroWhAI/RemoteWebBrowser/9368afc14946081505b21f9c1e2f6724eb685413/Resources/demo.PNG
--------------------------------------------------------------------------------
/Resources/desc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeuroWhAI/RemoteWebBrowser/9368afc14946081505b21f9c1e2f6724eb685413/Resources/desc.png
--------------------------------------------------------------------------------
/Resources/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NeuroWhAI/RemoteWebBrowser/9368afc14946081505b21f9c1e2f6724eb685413/Resources/icon.ico
--------------------------------------------------------------------------------