protected override void OnStartup(StartupEventArgs e) { // -Key (Value = null) or -Key=Value CommandLineArgs = e.Args .Select(x => x.Split(new[] { '=', }, 2)) .GroupBy(xs => xs[0], (k, ys) => ys.Last()) // 重複の場合は後ろの引数を優先 .ToDictionary(xs => xs[0], xs => xs.Length == 1 ? null : xs[1], StringComparer.OrdinalIgnoreCase); #if !DEBUG var appInstance = new MetroTrilithon.Desktop.ApplicationInstance().AddTo(this); if (appInstance.IsFirst || CommandLineArgs.ContainsKey(RestartedArg)) #endif { if (VirtualDesktop.IsSupported) { this.ShutdownMode = ShutdownMode.OnExplicitShutdown; this.DispatcherUnhandledException += (sender, args) => { ReportException(sender, args.Exception); args.Handled = true; }; //var pinnedapps = WindowsDesktop.Interop.VirtualDesktopInteropHelper.GetVirtualDesktopPinnedApps(); //Debug.WriteLine($"IsPinnedWindow: {pinnedapps.IsPinnedWindow(MetroRadiance.Interop.Win32.User32.GetForegroundWindow())}"); //Debug.WriteLine($"IsPinnedApp : {pinnedapps.IsPinnedApp(MetroRadiance.Interop.Win32.User32.GetForegroundWindow())}"); DispatcherHelper.UIDispatcher = this.Dispatcher; LocalSettingsProvider.Instance.LoadAsync().Wait(); LocalSettingsProvider.Instance.AddTo(this); ThemeService.Current.Register(this, Theme.Windows, Accent.Windows); this.ShowNotifyIcon(CommandLineArgs.ContainsKey(CanOpenSettingsArg)); this.VdmHelper = VdmHelperFactory.CreateInstance().AddTo(this); this.VdmHelper.Init(); this.HookService = new HookService(this.VdmHelper).AddTo(this); this.InteropService = new UwpInteropService(this.HookService, Settings.General).AddTo(this); this.RegisterActions(); NotificationService.Instance.AddTo(this); WallpaperService.Instance.AddTo(this); base.OnStartup(e); } else { MessageBox.Show("This applications is supported only Windows 10 (build 10240).", "Not supported", MessageBoxButton.OK, MessageBoxImage.Stop); this.Shutdown(); } } #if !DEBUG else { appInstance.SendCommandLineArgs(e.Args); this.Shutdown(); } #endif }
public VirtualDesktopGridManager(SysTrayProcess sysTrayProcess, SettingValues settings) { this.settings = settings; this.sysTrayProcess = sysTrayProcess; VDMHelper = VdmHelperFactory.CreateInstance(); VDMHelper.Init(); foregroundWindowChangedDelegate = new WinAPI.WinEventDelegate(ForegroundWindowChanged); fgWindowHook = WinAPI.SetWinEventHook(WinAPI.EVENT_SYSTEM_FOREGROUND, WinAPI.EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, foregroundWindowChangedDelegate, 0, 0, WinAPI.WINEVENT_OUTOFCONTEXT); // Create a custom message ID for other processes to trigger actions. commandWindowMessage = RegisterWindowMessage("VIRTUALDESKTOPGRIDSWITCHER_COMMAND"); Application.AddMessageFilter(this); Start(); }