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); } }
/// <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(); rks.Close(); rk.Close(); if (args == null || Dispatcher == null) return; Action<bool> d = (bool x) => { var win = MainWindow as MainWindow; if (win == null) return; win.ApendArgs(args.CommandLineArgs); //win.Activate(x); if (x) { ShellObject sho = null; if (args != null && args.CommandLineArgs != null) { if (args.CommandLineArgs.Length > 1 && args.CommandLineArgs[1] != null) { if (args.CommandLineArgs[1] != "t") { if (args.CommandLineArgs[1] == "nw") { BetterExplorer.MainWindow g = new MainWindow(); g.Show(); return; } else { String cmd = args.CommandLineArgs[1]; if (cmd.IndexOf("::") == 0) { sho = ShellObject.FromParsingName("shell:" + cmd); } else sho = ShellObject.FromParsingName(args.CommandLineArgs[1].Replace("\"", "")); } } else { if (StartUpLocation.IndexOf("::") == 0 && StartUpLocation.IndexOf(@"\") == -1) sho = ShellObject.FromParsingName("shell:" + StartUpLocation); else try { sho = ShellObject.FromParsingName(StartUpLocation); } catch { sho = (ShellObject)KnownFolders.Libraries; } } } else if (StartUpLocation.IndexOf("::") == 0 && StartUpLocation.IndexOf(@"\") == -1) sho = ShellObject.FromParsingName("shell:" + StartUpLocation); else try { sho = ShellObject.FromParsingName(StartUpLocation); } catch { sho = (ShellObject)KnownFolders.Libraries; } sho.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly; sho.Thumbnail.CurrentSize = new Size(16, 16); CloseableTabItem newt = new CloseableTabItem(); newt.Header = sho.GetDisplayName(DisplayNameType.Default); newt.TabIcon = sho.Thumbnail.BitmapSource; newt.Path = sho; win.CloneTab(newt); win.NavigateAfterTabChange(); IntPtr MainWinHandle = WindowsHelper.WindowsAPI.FindWindow(null, Process.GetCurrentProcess().MainWindowTitle); if (win.WindowState == WindowState.Minimized) { WindowsHelper.WindowsAPI.ShowWindow((int)MainWinHandle, (int)WindowsHelper.WindowsAPI.ShowCommands.SW_RESTORE); } WindowsHelper.WindowsAPI.BringWindowToTop(MainWinHandle); WindowsHelper.WindowsAPI.SetForegroundWindow(MainWinHandle); win.Activate(); } } }; Dispatcher.BeginInvoke(d, true); }
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> /// 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 = Utilities.GetRegistryValue("StartUpLoc", KnownFolders.Libraries.ParsingName).ToString(); Action<Boolean> d = x => { var win = this.MainWindow as MainWindow; var windowsActivate = new CombinedWindowActivator(); if (!x) { return; } if (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 ((Int32)Utilities.GetRegistryValue("IsRestoreTabs", "1") == 0) { 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(20000)) { Action d = () => { if (args != null && args.CommandLineArgs.Length > 1) { MainForm.UseCommandLineArg(args.CommandLineArgs[1]); } }; MainForm.Invoke(d); } }