123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using Microsoft.Win32;
- using System.Diagnostics;
- using System.IO;
- namespace WinBox
- {
- public partial class MainForm : Form
- {
- private CloseForm closeForm;
- private System.Windows.Forms.WebBrowser webBrowser1;
- public MainForm()
- {
- InitializeComponent();
- }
- /// <summary>
- /// 窗体加载
- /// </summary>
- private void Form1_Load(object sender, EventArgs e)
- {
- closeForm = new CloseForm();
- //设置IE版本
- SetIE(IeVersion.标准ie11);
- this.webBrowser1 = new System.Windows.Forms.WebBrowser();
- this.webBrowser1.Location = new System.Drawing.Point(0, 0);
- this.webBrowser1.MinimumSize = new System.Drawing.Size(0, 0);
- this.webBrowser1.Size = new System.Drawing.Size(Screen.GetWorkingArea(this).Width + 20, Screen.GetWorkingArea(this).Height);
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);
- this.webBrowser1.TabIndex = 2;
- this.webBrowser1.ScriptErrorsSuppressed = true;
- //页面URL
- this.webBrowser1.Url = new System.Uri("http://tt-web.api.ai160.com/debug/build/stage/index/index.html", System.UriKind.Absolute);
- this.Controls.Add(this.webBrowser1);
- // RunBat("C:\\Lingjiao\\winBoxNode\\start.bat");
- }
- private void Form1_Activated(object sender, System.EventArgs e)
- {
- // Label1.Text = "x: " + x + " y: " + y;
- // Label2.Text = "Number of forms currently open: " + count;
- string tcpPort = "9191";
- try
- {
- if (tcpPort == "" || tcpPort == null)
- {
- MessageBox.Show("请输入TCP端口号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- }
- else
- {
- Process process = new Process();
- process.StartInfo = new ProcessStartInfo("netstat", "/ano");
- process.StartInfo.CreateNoWindow = true;
- process.StartInfo.UseShellExecute = false;
- process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
- process.StartInfo.RedirectStandardOutput = true;
- process.Start();
- StreamReader reader = process.StandardOutput;
- while (!reader.EndOfStream)
- {
- string msg = reader.ReadLine().ToUpper();
- if (msg.IndexOf("TCP") > 0 && msg.IndexOf(":" + tcpPort) > 0)
- {
- string info = msg.Trim();
- MessageBox.Show("TCP:" + tcpPort + "端口被占用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- break;
- }
- else
- {
- MessageBox.Show("TCP:" + tcpPort + "端口没有被占用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- break;
- }
- }
-
- reader.Close();
- process.Close();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("检测TCP端口:" + tcpPort + "失败!" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- }
- }
- private void RunBat(string batPath)
- {
- Process pro = new Process();
- FileInfo file = new FileInfo(batPath);
- pro.StartInfo.WorkingDirectory = file.Directory.FullName;
- pro.StartInfo.FileName = batPath;
- pro.StartInfo.CreateNoWindow = false;
- pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
- pro.Start();
- pro.Close();
- }
- private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- }
- /// <summary>
- /// 定义IE版本的枚举
- /// </summary>
- private enum IeVersion
- {
- 标准ie11,//11000 (0×2af8)
- 强制ie10,//10001 (0x2711) Internet Explorer 10。网页以IE 10的标准模式展现,页面!DOCTYPE无效
- 标准ie10,//10000 (0x02710) Internet Explorer 10。在IE 10标准模式中按照网页上!DOCTYPE指令来显示网页。Internet Explorer 10 默认值。
- 强制ie9,//9999 (0x270F) Windows Internet Explorer 9. 强制IE9显示,忽略!DOCTYPE指令
- 标准ie9,//9000 (0x2328) Internet Explorer 9. Internet Explorer 9默认值,在IE9标准模式中按照网页上!DOCTYPE指令来显示网页。
- 强制ie8,//8888 (0x22B8) Internet Explorer 8,强制IE8标准模式显示,忽略!DOCTYPE指令
- 标准ie8,//8000 (0x1F40) Internet Explorer 8默认设置,在IE8标准模式中按照网页上!DOCTYPE指令展示网页
- 标准ie7//7000 (0x1B58) 使用WebBrowser Control控件的应用程序所使用的默认值,在IE7标准模式中按照网页上!DOCTYPE指令来展示网页
- }
- /// <summary>
- /// 设置WebBrowser的默认版本
- /// </summary>
- /// <param name="ver">IE版本</param>
- private void SetIE(IeVersion ver)
- {
- string productName = AppDomain.CurrentDomain.SetupInformation.ApplicationName;//获取程序名称
- object version;
- switch (ver)
- {
- case IeVersion.标准ie7:
- version = 0x1B58;
- break;
- case IeVersion.标准ie8:
- version = 0x1F40;
- break;
- case IeVersion.强制ie8:
- version = 0x22B8;
- break;
- case IeVersion.标准ie9:
- version = 0x2328;
- break;
- case IeVersion.强制ie9:
- version = 0x270F;
- break;
- case IeVersion.标准ie10:
- version = 0x02710;
- break;
- case IeVersion.强制ie10:
- version = 0x2711;
- break;
- case IeVersion.标准ie11:
- version = 0x2af8;
- break;
- default:
- version = 0x1F40;
- break;
- }
- RegistryKey key = Registry.CurrentUser;
- RegistryKey software =
- key.CreateSubKey(
- @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\" + productName);
- if (software != null)
- {
- software.Close();
- software.Dispose();
- }
- RegistryKey wwui =
- key.OpenSubKey(
- @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
- //该项必须已存在
- if (wwui != null) wwui.SetValue(productName, version, RegistryValueKind.DWord);
- }
- private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
- {
- CloseForm f = new CloseForm(this);
- this.Hide();
- f.ShowDialog();
-
- //MainForm.Hide();
- }
- }
- }
|