| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using CefSharp;
- using CefSharp.WinForms;
- using System.Configuration;
- using System.Drawing.Drawing2D;
- using System.Runtime.InteropServices;
- using System.Xml;
- using System.Threading;
- using System.Diagnostics;
- using System.Net;
- using CefSharp.WinForms.Internals;
- namespace Lecall
- {
- public partial class FrmMain : Form
- {
- public string ServerURL = "";
- public string PhoneNum = "";
- public static string MainURL = "";
- public FrmMain()
- {
- //InitializeComponent();
- //this.WindowState = FormWindowState.Maximized;
- //InitializeChromium();
- // Register an object in javascript named "cefCustomObject" with function of the CefCustomObject class :3
- //chromeBrowser.RegisterJsObject("formProcess", new FormProcess(chromeBrowser, this));
- //MessageBox.Show("4");
- InitializeComponent();
- //MessageBox.Show("1");
-
- }
- private void OnBrowserTitleChanged(object sender, TitleChangedEventArgs args)
- {
- this.InvokeOnUiThreadIfRequired(() => Text = args.Title);
- }
- private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
- {
- if (this.IsHandleCreated)
- {
- this.BeginInvoke(new MethodInvoker(() =>
- {
- if (this.IsHandleCreated && !this.IsDisposed)
- {
- if (this.toolTip1.Active)
- {
- this.toolTip1.Hide(this);
- }
- }
- }));
- }
- if (e.PropertyName == "TooltipText") //tooltipText改变事件
- {
- string tooltipText = this.wb.TooltipText;
- Point elementPos = new Point(Cursor.Position.X - this.Location.X, Cursor.Position.Y - this.Location.Y);
- if (!String.IsNullOrEmpty(tooltipText))
- {
- this.Invoke(new MethodInvoker(() =>
- {
- System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
- timer.Interval = 600;
- timer.Tick += (timer_sender, timer_e) =>
- {
- Point nowPos = new Point(Cursor.Position.X - this.Location.X, Cursor.Position.Y - this.Location.Y);
- //if ((nowPos.X <= elementPos.X + 20 && nowPos.X >= elementPos.X - 20) && (nowPos.Y <= elementPos.Y + 20 && nowPos.Y >= elementPos.Y - 20)) //鼠标停留了500ms(范围限定在一定范围)
- if (this.wb.TooltipText == tooltipText) //600毫秒后,tooltipText没变
- {
- this.toolTip1.Show(tooltipText, this, nowPos.X + 15, nowPos.Y + 15);
- }
- (timer_sender as System.Windows.Forms.Timer).Stop();
- (timer_sender as System.Windows.Forms.Timer).Dispose();
- };
- timer.Start();
- }));
- }
- }
- }
- ChromiumWebBrowser wb;
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- Cef.Shutdown();
- }
- private void Form1_KeyDown(object sender, KeyEventArgs e)
- {
- /*if (e.Control && e.KeyCode == Keys.F1)
- {
- //设置服务器地址
- string inputcap = InputBox("基础设置", "请输入服务器地址:", ServerURL);
- if (inputcap != null && inputcap != "")
- {
- string path = Environment.CurrentDirectory + @"\Config.ini"; //指定ini文件的路径
- IniFile ini = new IniFile(path);
- ini.IniWriteValue("基础设置", "服务器地址", inputcap);//string FpOrderNumber = ini.IniReadValue("登录设置", "服务器地址");//将tsslMo.Text的值写到键FpOrderNumber中去
- //重新加载页面
- this.Controls.Remove(wb);
- //设置停靠方式
- wb.Dock = DockStyle.Fill;
-
- //加入到当前窗体中
- this.Controls.Add(wb);
- }
- }*/
- }
- #region InputForm
- private string[] InputBox(string Caption, string Hint, string Default, string Hint1, string Default1)
- {
- Form InputForm = new Form();
- InputForm.MinimizeBox = false;
- InputForm.MaximizeBox = false;
- InputForm.StartPosition = FormStartPosition.CenterScreen;
- InputForm.Width = 380;
- InputForm.Height = 150;
- InputForm.FormBorderStyle = FormBorderStyle.FixedSingle;
- InputForm.Font = new Font("微软雅黑", 9, FontStyle.Regular);
- //InputForm.Font.Size = 10;
- InputForm.ShowIcon = false;
- InputForm.Text = Caption;
- Label lbl = new Label();
- lbl.Text = Hint;
- lbl.Left = 10;
- lbl.Top = 20;
- lbl.Parent = InputForm;
- lbl.AutoSize = true;
- TextBox tb = new TextBox();
- //tb.PasswordChar = '*';
- tb.Left = 85;
- tb.Top = 18;
- tb.Width = 260;
- tb.Parent = InputForm;
- tb.Text = Default;
- tb.SelectAll();
- //2017-8-5
- Label lbl1 = new Label();
- lbl1.Text = Hint1;
- lbl1.Left = 35;
- lbl1.Top = 50;
- lbl1.Parent = InputForm;
- lbl1.AutoSize = true;
- TextBox tb1 = new TextBox();
- //tb.PasswordChar = '*';
- tb1.Left = 85;
- tb1.Top = 48;
- tb1.Width = 260;
- tb1.Parent = InputForm;
- tb1.Text = Default1;
- Button btnok = new Button();
- btnok.Left = 100;
- btnok.Top = 80;
- btnok.Parent = InputForm;
- btnok.Text = "确定";
- InputForm.AcceptButton = btnok;//回车响应
- btnok.DialogResult = DialogResult.OK;
- Button btncancal = new Button();
- btncancal.Left = 190;
- btncancal.Top = 80;
- btncancal.Parent = InputForm;
- btncancal.Text = "取消";
- btncancal.DialogResult = DialogResult.Cancel;
- try
- {
- if (InputForm.ShowDialog() == DialogResult.OK)
- {
- string[] inputcap=new string[2];
- inputcap[0] = tb.Text;
- inputcap[1] = tb1.Text;
- return inputcap;
- }
- else
- {
- return null;
- }
- }
- finally
- {
- InputForm.Dispose();
- }
- }
- #endregion
- #region
- /*[DllImport("User32.dll")]
- private static extern IntPtr GetWindowDC(IntPtr hwnd);
- [DllImport("User32.dll")]
- private static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc);
- [DllImport("Kernel32.dll")]
- private static extern int GetLastError();
- Rectangle m_rect = new Rectangle(800, 10, 80, 20);
- protected override void WndProc(ref Message m)
- {
- //拦截双击标题栏、移动窗体的系统消息
- //if (m.Msg != 0xA3 && m.Msg != 0x0003 && m.WParam != (IntPtr)0xF012)
- //{
- // base.WndProc(ref m);
- //}
- base.WndProc(ref m);
- switch (m.Msg)
- {
- case 0x86://WM_NCACTIVATE
- goto case 0x85;
- case 0x85://WM_NCPAINT
- {
- IntPtr hDC = GetWindowDC(m.HWnd);
- //把DC转换为.NET的Graphics就可以很方便地使用Framework提供的绘图功能了
- Graphics gs = Graphics.FromHdc(hDC);
- //Graphics gs = this .CreateGraphics();
- gs.FillRectangle(new LinearGradientBrush(m_rect, Color.Transparent, Color.Transparent, LinearGradientMode.BackwardDiagonal), m_rect);
- //gs.FillRectangle(new LinearGradientBrush(m_rect, Color.Pink, Color.Purple, LinearGradientMode.BackwardDiagonal), m_rect);
- StringFormat strFmt = new StringFormat();
- strFmt.Alignment = StringAlignment.Center;
- strFmt.LineAlignment = StringAlignment.Center;
- gs.DrawString("基础设置", this.Font, Brushes.DarkSlateGray, m_rect, strFmt);//▲
- //gs.DrawString("设置", this.Font, Brushes.BlanchedAlmond, m_rect, strFmt);//▲
- gs.Dispose();
- //释放GDI资源
- ReleaseDC(m.HWnd, hDC);
- break;
- }
- case 0xA1://WM_NCLBUTTONDOWN
- {
- Point mousePoint = new Point((int)m.LParam);
- mousePoint.Offset(-this.Left, -this.Top);
- if (m_rect.Contains(mousePoint))
- {
- wb.ShowDevTools();
- //MessageBox.Show("hello");
- //设置服务器地址
- string inputcap = InputBox("基础设置", "请输入服务器地址:", ServerURL);
- if (inputcap != null && inputcap != "")
- {
- string path = Environment.CurrentDirectory + @"\Config.ini"; //指定ini文件的路径
- IniFile ini = new IniFile(path);
- ini.IniWriteValue("基础设置", "服务器地址", inputcap);//string FpOrderNumber = ini.IniReadValue("登录设置", "服务器地址");//将tsslMo.Text的值写到键FpOrderNumber中去
- //重新加载页面
- this.Controls.Remove(wb);
- wb = new ChromiumWebBrowser(inputcap);
- //设置停靠方式
- wb.Dock = DockStyle.Fill;
- //加入到当前窗体中
- this.Controls.Add(wb);
- }
- }
- break;
- }
- case 0xA3://WM_NCACTIVATE
- m.WParam = System.IntPtr.Zero;
- //this.WindowState = FormWindowState.Maximized;
- break;
- case 0xA9://WM_NCACTIVATE
- break;
- }
- }
- private void Form1_SizeChanged(object sender, EventArgs e)
- {
- m_rect = new Rectangle(this.Size.Width - 190, 10, 80, 20);
- }*/
- #endregion
- private void Form1_Load(object sender, EventArgs e)
- {
- //Rectangle rect = System.Windows.Forms.SystemInformation.VirtualScreen; int width = rect.Width; int height = rect.Height;
- ////this.MaximumSize = new Size(width, height);
- //this.MinimumSize = new Size(width, height);
- //this.WindowState = FormWindowState.Maximized;
- //IntPtr test = FindWindowEx(0, 0, "Shell_TrayWnd", "");
- //Console.WriteLine(test.ToString());
- //int test5 = SetWindowPos(test, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW);
- //this.TopMost = true;
- //this.FormBorderStyle = FormBorderStyle.None;
- //this.Width = Screen.PrimaryScreen.Bounds.Width;
- //this.Height = Screen.PrimaryScreen.Bounds.Height;
- //this.Top = 0;
- //this.Left = 0;
- #region 2017-10-31
- this.WindowState = FormWindowState.Maximized;
- //必须进行初始化,否则就出来页面啦。
- #region 2017-8-30测试
- //var setting = new CefSharp.CefSettings();
- //setting.Locale = "zh-CN";
- ////缓存路径
- //setting.CachePath = "/BrowserCache";
- ////浏览器引擎的语言
- //setting.AcceptLanguageList = "zh-CN,zh;q=0.8";
- //setting.LocalesDirPath = "/localeDir";
- ////日志文件
- //setting.LogFile = "/LogData";
- //setting.PersistSessionCookies = true;
- //setting.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36";
- //setting.UserDataPath = "/userData";
- //CefSharp.Cef.Initialize(setting);
- #endregion
- CefSettings settings = new CefSettings();
- settings.Locale = "zh-CN";
- settings.AcceptLanguageList = "zh-CN";
- Cef.Initialize(settings);
- //CefSharp.Cef.Initialize();
- string path = Environment.CurrentDirectory + @"\Config.ini"; //指定ini文件的路径
- //MessageBox.Show("2");
- IniFile ini = new IniFile(path);
- //MessageBox.Show("3");
- ServerURL = ini.IniReadValue("基础设置", "服务器地址");
- PhoneNum = ini.IniReadValue("基础设置", "分机号");
- MainURL = ini.IniReadValue("软件升级设置", "服务器地址");
- //MessageBox.Show(ServerURL);
- //实例化控件
- wb = new CefSharp.WinForms.ChromiumWebBrowser(ServerURL);
- //wb = new ChromiumWebBrowser(ServerURL);
- //设置停靠方式
- wb.Dock = DockStyle.Fill;
- //设置cookie
- var mngr = Cef.GetGlobalCookieManager();
- CefSharp.Cookie Ac = new CefSharp.Cookie();
- Ac.Name = "extno";
- Ac.Value = PhoneNum;
- Ac.Expires = DateTime.MinValue;
- mngr.SetCookieAsync(ServerURL, Ac);
- //加入到当前窗体中
- this.panel1.Controls.Add(wb);
- wb.MenuHandler = new MenuHandler();
- wb.DownloadHandler = new DownloadHandler();
- //wb.PropertyChanged += OnPropertyChanged;
- //2017-10-30
- //wb.TitleChanged += OnBrowserTitleChanged;
- this.Text = "河南华谊乐呼呼叫中心V" + LocalVersion;
- #endregion
- }
- #region 全屏去任务栏
- /*public const int HWND_NOTOPMOST = -2;
- public const int SWP_SHOWWINDOW = 0x0040;
- [DllImport("user32.dll")]
- private static extern IntPtr FindWindowEx(int hwnd2, int hWnd2, string lpsz1, string lpsz2);
- [DllImport("user32.dll")]
- private static extern int GetWindowLong(IntPtr hwnd, int nIndex);
- [DllImport("user32.dll")]
- private static extern int SetWindowPos(IntPtr hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);*/
- #endregion
- string devToolsUrl;
- private void tbnDebug_Click(object sender, EventArgs e)
- {
- wb.ShowDevTools();
- }
- private void tbtbnSet_Click(object sender, EventArgs e)
- {
- //设置服务器地址
- string[] inputcap = InputBox("基础设置", "服务器地址:", ServerURL,"分机号:",PhoneNum);
- if (inputcap != null )
- {
- string path = Environment.CurrentDirectory + @"\Config.ini"; //指定ini文件的路径
- IniFile ini = new IniFile(path);
- ini.IniWriteValue("基础设置", "服务器地址", inputcap[0]);//string FpOrderNumber = ini.IniReadValue("登录设置", "服务器地址");//将tsslMo.Text的值写到键FpOrderNumber中去
- ini.IniWriteValue("基础设置", "分机号", inputcap[1]);
- ServerURL = inputcap[0];
- PhoneNum = inputcap[1];
- var request = WebRequest.Create(ServerURL) as HttpWebRequest;
- string x = request.Host;
- ini.IniWriteValue("软件升级设置", "服务器地址", "http://" + x);
- MainURL = "http://" + x;
- //2017-8-5将分机号写cookie
- //var cookieManager = CefSharp.Cef.GetGlobalCookieManager();
- //await cookieManager.SetCookieAsync(ServerURL,
- //new CefSharp.Cookie()
- //{
- // Domain = ServerURL,
- // Name = "extno",
- // Value = PhoneNum,
- // Expires = DateTime.MinValue
- //});
- //重新加载页面
- this.panel1 .Controls.Remove(wb);
- wb = new ChromiumWebBrowser(inputcap[0]);
- //设置停靠方式
- wb.Dock = DockStyle.Fill;
- //分机号设置cookie
- var mngr = Cef.GetGlobalCookieManager();
- CefSharp.Cookie Ac = new CefSharp.Cookie();
- Ac.Name = "extno";
- Ac.Value = PhoneNum;
- Ac.Expires = DateTime.MinValue;
- mngr.SetCookieAsync(ServerURL, Ac);
- //加入到当前窗体中
- this.panel1.Controls.Add(wb);
- }
- }
- /// <summary>
- /// 显示调试窗口
- /// </summary>
- /*public void ShowDevWin()
- {
- try
- {
- if (string.IsNullOrEmpty(devToolsUrl))
- {
- devToolsUrl = web_view.Browser.GetHost().GetDevToolsUrl(true);
- wb.ShowDevTools();
- }
- var frame = web_view.Browser.GetMainFrame();
- //frame.ExecuteJavaScript(string.Format("window.open('{0}');", devToolsUrl), "about:blank", 0);
- var p = Process.Start(devToolsUrl);
- }
- catch
- {
- MessageBox.Show("请等待页面加载完成之后再打开调试器");
- }
- }*/
- public static string LocalVersion = "";
- #region 判断是否更新版本
- /// <summary>
- /// 判断是否更新
- /// </summary>
- private static void Update()
- {
- try
- {
- //获取当前程序的版本号 比较进行升级
-
- LocalVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
- string xmlFilePath = MainURL+@"/LecallUpdate/Update.xml?v=" + System.DateTime.Now.ToString("yyyyMMddhhmmss");
- //string strHTML = Commoon.HttpWeb.GetHTML(xmlFilePath);
- //Commoon.XmlHelper xml = new Commoon.XmlHelper();
- //xml.LoadXml(strHTML);
- XmlDocument doc = new XmlDocument();
- doc.Load(xmlFilePath);
- XmlElement root = doc.DocumentElement;
- XmlNode versionNode = root.SelectSingleNode("version");
- string DistalVersion = versionNode.InnerText;
- if (DistalVersion != LocalVersion)
- {
- frmUpdateMsg frmupdatemsg = new frmUpdateMsg();
- frmupdatemsg.Msg = root.SelectSingleNode("description").InnerText;
- frmupdatemsg.ShowDialog();
- }
- }
- catch
- {
- //InfoLog.frmLog frmlog = new InfoLog.frmLog();
- //frmlog.AddLog("验证新版本出现问题");
- }
- }
- #endregion
- [DllImport("user32.dll")]//设置窗体位活动窗体
- private static extern bool SetForegroundWindow(IntPtr hWnd);
- [DllImport("user32.dll")]//设置窗体状态
- private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
- private const int SW_RESTORE = 9; //用原来的大小和位置显示一个窗口
- [STAThread]
- static void Main()
- {
- bool createForm = false;//是否创建引用
- using (Mutex mutex = new Mutex(true, "ATT", out createForm))
- {
- //MessageBox.Show("5");
- if (createForm)
- {//如果系统中不存在"AHookProgram"元素 则创建窗体
- //Application.EnableVisualStyles();
- //Application.SetCompatibleTextRenderingDefault(false);
- //MessageBox.Show("6");
- #region 版本判断是否更新
- string path = Environment.CurrentDirectory + @"\Config.ini"; //指定ini文件的路径
- IniFile ini = new IniFile(path);
- MainURL = ini.IniReadValue("软件升级设置", "服务器地址");
- Update();
- #endregion
- //MessageBox.Show("7");
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new FrmMain());
-
- }
- else
- {//如果系统中存在"AHookProgram"元素 则表明程序已经运行
- //MessageBox.Show("程序已经运行在进程中!", "提示");
- //遍历进程根据进程名找寻窗体
- //MessageBox.Show("8");
- Process current = Process.GetCurrentProcess();
- foreach (Process p in Process.GetProcessesByName(current.ProcessName))
- {
- //MessageBox.Show("9");
- if (p.Id != current.Id)
- {//会查上来两个 将不是自己的那个显示出来
- //MessageBox.Show("10");
- SetForegroundWindow(p.MainWindowHandle);//激活窗体
- ShowWindowAsync(p.MainWindowHandle, SW_RESTORE);//设置窗体状态
- }
- }
- }
- }
- }
- private void FrmMain_FormClosed(object sender, FormClosedEventArgs e)
- {
- System.Environment.Exit(0);
- }
- }
- }
|