private static void SingleInstanceCallback(object sender, InstanceCallbackEventArgs args) { if (WaitFormLoad(5000)) { Action d = () => { if (args.CommandLineArgs == null || args.CommandLineArgs.Length <= 1) { if (MainForm.niTray != null && MainForm.niTray.Visible) { // Workaround for Windows startup tray icon bug MainForm.niTray.Visible = false; MainForm.niTray.Visible = true; } MainForm.ShowActivate(); } else if (MainForm.Visible) { MainForm.ShowActivate(); } MainForm.UseCommandLineArgs(args.CommandLineArgs); }; MainForm.InvokeSafe(d); } }
private static void SingleInstanceCallback(object sender, InstanceCallbackEventArgs args) { if (WaitFormLoad(3000)) { Action d = () => { mainForm.ForceActivate(); mainForm.LoadItems(args.CommandLineArgs.OnlyValidFiles()); }; mainForm.InvokeSafe(d); } }
private static void SingleInstanceCallback(object sender, InstanceCallbackEventArgs args) { if (WaitFormLoad(20000)) { Action d = () => { if (args != null && args.CommandLineArgs.Length > 1) { MainForm.UseCommandLineArg(args.CommandLineArgs[1]); } }; MainForm.Invoke(d); } }
private static void SingleInstanceCallback(object sender, InstanceCallbackEventArgs args) { if (WaitFormLoad(5000)) { Action d = () => { if (mainForm.Visible) { mainForm.ShowActivate(); } mainForm.UseCommandLineArgs(args.CommandLineArgs); }; mainForm.Invoke(d); } }
/// <summary> /// Handler that gets called if another instance of the application was started. It passes /// the command line arguments from the other instance on so we can act accordingly here. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The instance containing the event data.</param> private static void SingleInstanceCallback(object sender, InstanceCallbackEventArgs args) { if (args == null || mainForm == null || !mainForm.IsHandleCreated) { return; } Action <bool> d = (bool x) => { mainForm.Activate(x); // Parse command line and extract the model file name if there is one. WbOptions options = new WbOptions("", "", false); System.Reflection.Assembly asm = System.Reflection.Assembly.GetEntryAssembly(); options.parse_args(args.CommandLineArgs, asm.Location); wbContext.finished_loading(options); }; mainForm.Invoke(d, true); }
/// <summary> /// Single instance callback handler. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="SingleInstanceApplication.InstanceCallbackEventArgs"/> instance containing the event data.</param> private void SingleInstanceCallback(Object sender, InstanceCallbackEventArgs args) { if (args == null || this.Dispatcher == null) { return; } var startUpLocation = Settings.BESettings.StartupLocation; Action <Boolean> d = x => { var win = this.MainWindow as MainWindow; var windowsActivate = new CombinedWindowActivator(); if (!x || win == null) { return; } win.StateChanged += this.Win_StateChanged; if (args.CommandLineArgs == null || !args.CommandLineArgs.Any()) { return; } if (args.CommandLineArgs.Length == 1) { win.Visibility = Visibility.Visible; windowsActivate.ActivateForm(win, null, IntPtr.Zero); } else { if (args.CommandLineArgs[1] == "/nw") { new MainWindow() { IsMultipleWindowsOpened = true }.Show(); } else { IListItemEx sho; if (args.CommandLineArgs[1] == "t") { win.Visibility = Visibility.Visible; windowsActivate.ActivateForm(win, null, IntPtr.Zero); sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, startUpLocation.ToShellParsingName()); } else { sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, args.CommandLineArgs[1].ToShellParsingName()); } if (!IsStartMinimized || win.tcMain.Items.Count == 0) { this.CreateInitialTab(win, sho); } else if (Settings.BESettings.IsRestoreTabs) { win.tcMain.Items.Clear(); this.CreateInitialTab(win, sho); } else if (args.CommandLineArgs.Length > 1 && args.CommandLineArgs[1] != null) { if (args.CommandLineArgs[1] == "t") { this.CreateInitialTab(win, sho); } else { var cmd = args.CommandLineArgs[1]; sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, cmd.ToShellParsingName()); this.CreateInitialTab(win, sho); } } else { this.CreateInitialTab(win, sho); } } windowsActivate.ActivateForm(win, null, IntPtr.Zero); } }; this.Dispatcher.BeginInvoke(d, true); }
private static void SingleInstanceCallback(object sender, InstanceCallbackEventArgs args) { if (WaitFormLoad(5000)) { Action d = () => { if (args.CommandLineArgs == null || args.CommandLineArgs.Length < 1) { if (MainForm.niTray != null && MainForm.niTray.Visible) { // Workaround for Windows startup tray icon bug MainForm.niTray.Visible = false; MainForm.niTray.Visible = true; } MainForm.ShowActivate(); } else if (MainForm.Visible) { MainForm.ShowActivate(); } CLIManager cli = new CLIManager(args.CommandLineArgs); cli.ParseCommands(); MainForm.UseCommandLineArgs(cli.Commands); }; MainForm.InvokeSafe(d); } }
/// <summary> /// Single instance callback handler. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="SingleInstanceApplication.InstanceCallbackEventArgs"/> instance containing the event data.</param> private void SingleInstanceCallback(object sender, InstanceCallbackEventArgs args) { string StartUpLocation = KnownFolders.Libraries.ParsingName; RegistryKey rk = Registry.CurrentUser; RegistryKey rks = rk.OpenSubKey(@"Software\BExplorer", false); StartUpLocation = rks.GetValue(@"StartUpLoc", KnownFolders.Libraries.ParsingName).ToString(); if (args == null || Dispatcher == null) { return; } Action <bool> d = (bool x) => { var win = MainWindow as MainWindow; if (win == null) { return; } var hwnd = (HwndSource.FromVisual(win) as HwndSource).Handle; win.ApendArgs(args.CommandLineArgs); if (x) { ShellItem sho = null; if (args != null && args.CommandLineArgs != null) { if (args.CommandLineArgs.Length > 1 && args.CommandLineArgs[1] != null && args.CommandLineArgs[1] != "-minimized") { if (args.CommandLineArgs[1] != "t") { if (args.CommandLineArgs[1] == "nw") { MainWindow g = new MainWindow(); g.Show(); return; } else { win.Visibility = Visibility.Visible; if (win.WindowState == WindowState.Minimized) { WindowsAPI.ShowWindow(hwnd, (int)WindowsAPI.ShowCommands.SW_RESTORE); } String cmd = args.CommandLineArgs[1]; if (cmd.IndexOf("::") == 0) { sho = new ShellItem("shell:" + cmd); } else { sho = new ShellItem(args.CommandLineArgs[1].Replace("\"", "")); } } } else { win.Visibility = Visibility.Visible; if (win.WindowState == WindowState.Minimized) { WindowsAPI.ShowWindow(hwnd, (int)WindowsAPI.ShowCommands.SW_RESTORE); } sho = new ShellItem(StartUpLocation); } } else { win.Visibility = Visibility.Visible; if (win.WindowState == WindowState.Minimized) { WindowsAPI.ShowWindow(hwnd, (int)WindowsAPI.ShowCommands.SW_RESTORE); } sho = new ShellItem(StartUpLocation); } if (!isStartMinimized || win.tabControl1.Items.Count == 0) { sho.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly; sho.Thumbnail.CurrentSize = new System.Windows.Size(16, 16); ClosableTabItem newt = new ClosableTabItem(); newt.Header = sho.GetDisplayName(SIGDN.NORMALDISPLAY); newt.TabIcon = sho.Thumbnail.BitmapSource; newt.PreviewMouseMove += newt_PreviewMouseMove; newt.ToolTip = sho.ParsingName; newt.TabSelected += win.newt_TabSelected; newt.Path = sho; win.CloneTab(newt); } else { int RestoreTabs = (int)rks.GetValue(@"IsRestoreTabs", 1); if (RestoreTabs == 0) { win.tabControl1.Items.Clear(); sho.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly; sho.Thumbnail.CurrentSize = new System.Windows.Size(16, 16); ClosableTabItem newt = new ClosableTabItem(); newt.Header = sho.GetDisplayName(SIGDN.NORMALDISPLAY); newt.TabIcon = sho.Thumbnail.BitmapSource; newt.PreviewMouseMove += newt_PreviewMouseMove; newt.ToolTip = sho.ParsingName; newt.TabSelected += win.newt_TabSelected; newt.Path = sho; win.CloneTab(newt); } if (args.CommandLineArgs.Length > 1 && args.CommandLineArgs[1] != null) { String cmd = args.CommandLineArgs[1]; if (cmd.IndexOf("::") == 0) { sho = new ShellItem("shell:" + cmd); } else { sho = new ShellItem(args.CommandLineArgs[1].Replace("\"", "")); } sho.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly; sho.Thumbnail.CurrentSize = new System.Windows.Size(16, 16); ClosableTabItem newt = new ClosableTabItem(); newt.Header = sho.GetDisplayName(SIGDN.NORMALDISPLAY); newt.TabIcon = sho.Thumbnail.BitmapSource; newt.PreviewMouseMove += newt_PreviewMouseMove; newt.ToolTip = sho.ParsingName; newt.TabSelected += win.newt_TabSelected; newt.Path = sho; win.CloneTab(newt); } } rks.Close(); rk.Close(); win.Activate(); win.Topmost = true; // important win.Topmost = false; // important win.Focus(); // important } } }; Dispatcher.BeginInvoke(d, true); }
/// <summary> /// Single instance callback handler. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="SingleInstanceApplication.InstanceCallbackEventArgs"/> instance containing the event data.</param> /// private void SingleInstanceCallback(Object sender, InstanceCallbackEventArgs args) { if (args == null || Dispatcher == null) { return; } var startUpLocation = Utilities.GetRegistryValue("StartUpLoc", KnownFolders.Libraries.ParsingName).ToString(); Action <Boolean> d = x => { var win = MainWindow as MainWindow; var windowsActivate = new CombinedWindowActivator(); if (!x) { return; } if (win == null) { return; } win.StateChanged += Win_StateChanged; if (args?.CommandLineArgs == null || !args.CommandLineArgs.Any()) { return; } if (args.CommandLineArgs.Length == 1) { win.Visibility = Visibility.Visible; //if (win.WindowState == WindowState.Minimized) { // User32.ShowWindow((PresentationSource.FromVisual(win) as HwndSource).Handle, User32.ShowWindowCommands.Restore); //} //User32.ForceForegroundWindow(win); windowsActivate.ActivateForm(win, null, IntPtr.Zero); } else { if (args.CommandLineArgs[1] == "/nw") { new MainWindow() { IsMultipleWindowsOpened = true }.Show(); } else { IListItemEx sho = null; if (args.CommandLineArgs[1] == "t") { win.Visibility = Visibility.Visible; //if (win.WindowState == WindowState.Minimized) // User32.ShowWindow((PresentationSource.FromVisual(win) as HwndSource).Handle, // User32.ShowWindowCommands.Restore); windowsActivate.ActivateForm(win, null, IntPtr.Zero); sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, startUpLocation.ToShellParsingName()); } else { sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, args.CommandLineArgs[1].ToShellParsingName()); } if (!IsStartMinimized || win.tcMain.Items.Count == 0) { CreateInitialTab(win, sho); } else if ((Int32)Utilities.GetRegistryValue("IsRestoreTabs", "1") == 0) { win.tcMain.Items.Clear(); CreateInitialTab(win, sho); } else if (args.CommandLineArgs.Length > 1 && args.CommandLineArgs[1] != null) { if (args.CommandLineArgs[1] == "t") { CreateInitialTab(win, sho); } else { var cmd = args.CommandLineArgs[1]; sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, cmd.ToShellParsingName()); CreateInitialTab(win, sho); } } else { CreateInitialTab(win, sho); } } //User32.ForceForegroundWindow(win); windowsActivate.ActivateForm(win, null, IntPtr.Zero); } }; Dispatcher.BeginInvoke(d, true); }