//using DevExpress.Compression; using DevExpress.Compression; using DevExpress.LookAndFeel; using DevExpress.XtraRichEdit.Model; using Ips.Library.Basic; using Ips.Library.DxpLib; using Ips.Library.DxpLib.Properties; using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace Ips.Library; public class AppHelper { public const string CultureName = "zh-CN"; public static void InitAppSettings() { Application.ThreadException += Application_ThreadException; Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; DevExpress.Utils.AppearanceObject.DefaultFont = new System.Drawing.Font("微软雅黑", 9); DevExpress.Skins.SkinManager.EnableFormSkins(); Application.ApplicationExit += (sender, e) => { ToolConfig.SetAppSetting("SkinName", UserLookAndFeel.Default.ActiveSkinName); ToolConfig.SetAppSetting("PaletteName", UserLookAndFeel.Default.ActiveSvgPaletteName); ToolConfig.SetAppSetting("CompactMode", UserLookAndFeel.Default.CompactUIModeForced); }; string skinName = ToolConfig.GetAppSetting("SkinName").IfNullOrWhitespace("WXI"); string paletteName = ToolConfig.GetAppSetting("PaletteName"); bool compactMode = ToolConfig.GetAppSetting("CompactMode").To(true); if (compactMode) UserLookAndFeel.ForceCompactUIMode(true, false); if (!string.IsNullOrEmpty(paletteName)) UserLookAndFeel.Default.SetSkinStyle(skinName, paletteName); else UserLookAndFeel.Default.SetSkinStyle(skinName); CultureInfo culture = CultureInfo.CreateSpecificCulture(CultureName); Application.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; Thread.CurrentThread.CurrentCulture = culture; CultureInfo.DefaultThreadCurrentCulture = culture; CultureInfo.DefaultThreadCurrentUICulture = culture; UserLookAndFeel.Default.StyleChanged += (sender, e) => { ToolConfig.SetAppSetting("SkinName", UserLookAndFeel.Default.ActiveSkinName); ToolConfig.SetAppSetting("PaletteName", UserLookAndFeel.Default.ActiveSvgPaletteName); }; } static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { string errMsg = "发生未知错误,请联系管理员!" + e.Exception?.Message; MsgHelper.ShowError(errMsg, e.Exception); } static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { var ex = e.ExceptionObject as Exception; if (ex == null) return; MsgHelper.ShowError("发生未知错误,程序即将退出!" + ex.Message, ex); } public static void OneStart(string appName, Action act) { using (Mutex mutex = new Mutex(true, appName)) { if (!mutex.WaitOne(0, false)) { Process currentProcess = Process.GetCurrentProcess(); Process[] processesByName = Process.GetProcessesByName(currentProcess.ProcessName); bool isShow = false; for (int i = 0; i < processesByName.Length; i++) { Process process = processesByName[i]; if (process.Id != currentProcess.Id && process.MainWindowHandle != IntPtr.Zero) { isShow = true; ToolWinApi.SetForegroundWindow(process.MainWindowHandle); ToolWinApi.RestoreWindowAsync(process.MainWindowHandle); break; } } if (!isShow) { MsgHelper.ShowMsg("已有相同程序在运行,不能重复启动!"); } } else { act(); } } } public static void MultStart(Action act) { act(); } }