123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- using CefSharp;
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Runtime.Serialization;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Timers;
- using System.Windows.Forms;
- namespace felixyin
- {
- static class Program
- {
- private static ApplicationContext context;
- // Will attempt to load missing assembly from either x86 or x64 subdir
- private static Assembly Resolver(object sender, ResolveEventArgs args)
- {
- if (args.Name.StartsWith("CefSharp"))
- {
- string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll";
- string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
- Environment.Is64BitProcess ? "x64" : "x86",
- assemblyName);
- return File.Exists(archSpecificPath)
- ? Assembly.LoadFile(archSpecificPath)
- : null;
- }
- return null;
- }
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main()
- {
- //Application.SetCompatibleTextRenderingDefault(false);
- Application.EnableVisualStyles();
- Application.DoEvents();
- AppDomain.CurrentDomain.AssemblyResolve += Resolver;
- MainForm mainForm = new MainForm();
- mainForm.Show();
- context = new ApplicationContext();
- context.Tag = mainForm;
- Application.Idle += new EventHandler(Application_Idle);
- Application.Run(context);
- // AutoStart(true);
- }
- private static void Application_Idle(object sender, EventArgs e)
- {
- Application.Idle -= new EventHandler(Application_Idle);
- if (context.MainForm == null)
- {
- SplashForm splashForm = new SplashForm();
- splashForm.Opacity = 1D;
- splashForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
- splashForm.Show();
- splashForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
- splashForm.ShowIcon = false;
- splashForm.ShowInTaskbar = false;
- splashForm.ControlBox = false;
- Thread.Sleep(3000);
- splashForm.Close();
- }
- }
- public static void showMainForm()
- {
- MainForm mainForm = (MainForm)context.Tag;
- context.MainForm = mainForm;
- /*
- mainForm.Opacity = 0.20D;
- Thread.Sleep(100);
- mainForm.Opacity = 0.40D;
- Thread.Sleep(100);
- mainForm.Opacity = 0.60D;
- Thread.Sleep(100);
- mainForm.Opacity = 0.80D;
- Thread.Sleep(100);
- */
- // Thread.Sleep(5000);
- mainForm.Opacity = 1D;
- }
- private static bool isShow = false;
- public static void toggleDevTools()
- {
- MainForm mainForm = (MainForm)context.Tag;
- context.MainForm = mainForm;
- if (isShow)
- {
- isShow = false;
- mainForm.webBrowser1.CloseDevTools();
- }
- else
- {
- isShow = true;
- mainForm.webBrowser1.ShowDevTools();
- }
- }
- /// <summary>
- /// 修改程序在注册表中的键值
- /// </summary>
- /// <param name="isAuto">true:开机启动,false:不开机自启</param>
- public static void AutoStart(bool isAuto)
- {
- try
- {
- if (isAuto == true)
- {
- RegistryKey R_local = Registry.LocalMachine;//RegistryKey R_local = Registry.CurrentUser;
- RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
- R_run.SetValue("佰安客工厂管理系统", Application.ExecutablePath);
- R_run.Close();
- R_local.Close();
- }
- else
- {
- RegistryKey R_local = Registry.LocalMachine;//RegistryKey R_local = Registry.CurrentUser;
- RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
- R_run.DeleteValue("佰安客工厂管理系统", false);
- R_run.Close();
- R_local.Close();
- }
- //GlobalVariant.Instance.UserConfig.AutoStart = isAuto;
- }
- catch (Exception)
- {
- //MessageBoxDlg dlg = new MessageBoxDlg();
- //dlg.InitialData("您需要管理员权限修改", "提示", MessageBoxButtons.OK, MessageBoxDlgIcon.Error);
- //dlg.ShowDialog();
- MessageBox.Show("程序未能设置随系统自动启动。\n可能被360、腾讯管家等软件阻止,\n或者需要管理员权限,请尝试右键以管理员运行", "佰安客科技提示");
- }
- }
- }
- }
|