Uses all the tricks in the book at once to do it...shady
Inheritance: WindowActivator
Example #1
0
 /// <summary>
 /// Rise on change of Main Window state
 /// </summary>
 /// <param name="sender">The main Window</param>
 /// <param name="e">The args</param>
 private void Win_StateChanged(Object sender, EventArgs e) {
   if ((sender as Window)?.WindowState != WindowState.Minimized) {
     ((Window)sender).Visibility = Visibility.Visible;
     CombinedWindowActivator windowsActivate = new CombinedWindowActivator();
     windowsActivate.ActivateForm(sender as Window, null, IntPtr.Zero);
   }
 }
Example #2
0
    /// <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);
    }