MainForm.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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.Windows.Forms;
  9. using Microsoft.Win32;
  10. using System.Diagnostics;
  11. using System.IO;
  12. namespace WinBox
  13. {
  14. public partial class MainForm : Form
  15. {
  16. private CloseForm closeForm;
  17. private System.Windows.Forms.WebBrowser webBrowser1;
  18. public MainForm()
  19. {
  20. InitializeComponent();
  21. }
  22. /// <summary>
  23. /// 窗体加载
  24. /// </summary>
  25. private void Form1_Load(object sender, EventArgs e)
  26. {
  27. closeForm = new CloseForm();
  28. //设置IE版本
  29. SetIE(IeVersion.标准ie11);
  30. this.webBrowser1 = new System.Windows.Forms.WebBrowser();
  31. this.webBrowser1.Location = new System.Drawing.Point(0, 0);
  32. this.webBrowser1.MinimumSize = new System.Drawing.Size(0, 0);
  33. this.webBrowser1.Size = new System.Drawing.Size(Screen.GetWorkingArea(this).Width + 20, Screen.GetWorkingArea(this).Height);
  34. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);
  35. this.webBrowser1.TabIndex = 2;
  36. this.webBrowser1.ScriptErrorsSuppressed = true;
  37. //页面URL
  38. this.webBrowser1.Url = new System.Uri("http://tt-web.api.ai160.com/debug/build/stage/index/index.html", System.UriKind.Absolute);
  39. this.Controls.Add(this.webBrowser1);
  40. // RunBat("C:\\Lingjiao\\winBoxNode\\start.bat");
  41. }
  42. private void Form1_Activated(object sender, System.EventArgs e)
  43. {
  44. // Label1.Text = "x: " + x + " y: " + y;
  45. // Label2.Text = "Number of forms currently open: " + count;
  46. string tcpPort = "9191";
  47. try
  48. {
  49. if (tcpPort == "" || tcpPort == null)
  50. {
  51. MessageBox.Show("请输入TCP端口号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  52. }
  53. else
  54. {
  55. Process process = new Process();
  56. process.StartInfo = new ProcessStartInfo("netstat", "/ano");
  57. process.StartInfo.CreateNoWindow = true;
  58. process.StartInfo.UseShellExecute = false;
  59. process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  60. process.StartInfo.RedirectStandardOutput = true;
  61. process.Start();
  62. StreamReader reader = process.StandardOutput;
  63. while (!reader.EndOfStream)
  64. {
  65. string msg = reader.ReadLine().ToUpper();
  66. if (msg.IndexOf("TCP") > 0 && msg.IndexOf(":" + tcpPort) > 0)
  67. {
  68. string info = msg.Trim();
  69. MessageBox.Show("TCP:" + tcpPort + "端口被占用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  70. break;
  71. }
  72. else
  73. {
  74. MessageBox.Show("TCP:" + tcpPort + "端口没有被占用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  75. break;
  76. }
  77. }
  78. reader.Close();
  79. process.Close();
  80. }
  81. }
  82. catch (Exception ex)
  83. {
  84. MessageBox.Show("检测TCP端口:" + tcpPort + "失败!" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  85. }
  86. }
  87. private void RunBat(string batPath)
  88. {
  89. Process pro = new Process();
  90. FileInfo file = new FileInfo(batPath);
  91. pro.StartInfo.WorkingDirectory = file.Directory.FullName;
  92. pro.StartInfo.FileName = batPath;
  93. pro.StartInfo.CreateNoWindow = false;
  94. pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  95. pro.Start();
  96. pro.Close();
  97. }
  98. private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
  99. {
  100. }
  101. /// <summary>
  102. /// 定义IE版本的枚举
  103. /// </summary>
  104. private enum IeVersion
  105. {
  106. 标准ie11,//11000 (0×2af8)
  107. 强制ie10,//10001 (0x2711) Internet Explorer 10。网页以IE 10的标准模式展现,页面!DOCTYPE无效
  108. 标准ie10,//10000 (0x02710) Internet Explorer 10。在IE 10标准模式中按照网页上!DOCTYPE指令来显示网页。Internet Explorer 10 默认值。
  109. 强制ie9,//9999 (0x270F) Windows Internet Explorer 9. 强制IE9显示,忽略!DOCTYPE指令
  110. 标准ie9,//9000 (0x2328) Internet Explorer 9. Internet Explorer 9默认值,在IE9标准模式中按照网页上!DOCTYPE指令来显示网页。
  111. 强制ie8,//8888 (0x22B8) Internet Explorer 8,强制IE8标准模式显示,忽略!DOCTYPE指令
  112. 标准ie8,//8000 (0x1F40) Internet Explorer 8默认设置,在IE8标准模式中按照网页上!DOCTYPE指令展示网页
  113. 标准ie7//7000 (0x1B58) 使用WebBrowser Control控件的应用程序所使用的默认值,在IE7标准模式中按照网页上!DOCTYPE指令来展示网页
  114. }
  115. /// <summary>
  116. /// 设置WebBrowser的默认版本
  117. /// </summary>
  118. /// <param name="ver">IE版本</param>
  119. private void SetIE(IeVersion ver)
  120. {
  121. string productName = AppDomain.CurrentDomain.SetupInformation.ApplicationName;//获取程序名称
  122. object version;
  123. switch (ver)
  124. {
  125. case IeVersion.标准ie7:
  126. version = 0x1B58;
  127. break;
  128. case IeVersion.标准ie8:
  129. version = 0x1F40;
  130. break;
  131. case IeVersion.强制ie8:
  132. version = 0x22B8;
  133. break;
  134. case IeVersion.标准ie9:
  135. version = 0x2328;
  136. break;
  137. case IeVersion.强制ie9:
  138. version = 0x270F;
  139. break;
  140. case IeVersion.标准ie10:
  141. version = 0x02710;
  142. break;
  143. case IeVersion.强制ie10:
  144. version = 0x2711;
  145. break;
  146. case IeVersion.标准ie11:
  147. version = 0x2af8;
  148. break;
  149. default:
  150. version = 0x1F40;
  151. break;
  152. }
  153. RegistryKey key = Registry.CurrentUser;
  154. RegistryKey software =
  155. key.CreateSubKey(
  156. @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\" + productName);
  157. if (software != null)
  158. {
  159. software.Close();
  160. software.Dispose();
  161. }
  162. RegistryKey wwui =
  163. key.OpenSubKey(
  164. @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
  165. //该项必须已存在
  166. if (wwui != null) wwui.SetValue(productName, version, RegistryValueKind.DWord);
  167. }
  168. private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
  169. {
  170. CloseForm f = new CloseForm(this);
  171. this.Hide();
  172. f.ShowDialog();
  173. //MainForm.Hide();
  174. }
  175. }
  176. }