コード例 #1
0
        void appStartup(object sender, StartupEventArgs e)
        {
            NumberOfRunningInstances = Process.GetProcessesByName("Text-Grab").Length;

            // Register COM server and activator type
            bool handledArgument = false;

            ToastNotificationManagerCompat.OnActivated += toastArgs =>
            {
                string argsInvoked = toastArgs.Argument;
                // Need to dispatch to UI thread if performing UI operations
                Dispatcher.BeginInvoke((Action)(() =>
                {
                    if (String.IsNullOrWhiteSpace(argsInvoked) == false)
                    {
                        EditTextWindow mtw = new EditTextWindow(argsInvoked);
                        mtw.Show();
                        handledArgument = true;
                    }
                }));
            };

            if (Settings.Default.RunInTheBackground == true &&
                NumberOfRunningInstances < 2)
            {
                NotifyIconUtilities.SetupNotifyIcon();
            }

            Current.DispatcherUnhandledException += CurrentDispatcherUnhandledException;

            for (int i = 0; i != e.Args.Length && !handledArgument; ++i)
            {
                Debug.WriteLine($"ARG {i}:{e.Args[i]}");
                if (e.Args[i].Contains("ToastActivated"))
                {
                    Debug.WriteLine("Launched from toast");
                    handledArgument = true;
                }
                else if (e.Args[i] == "Settings")
                {
                    SettingsWindow sw = new SettingsWindow();
                    sw.Show();
                    handledArgument = true;
                }
                else if (e.Args[i] == "GrabFrame")
                {
                    GrabFrame gf = new GrabFrame();
                    gf.Show();
                    handledArgument = true;
                }
                else if (e.Args[i] == "Fullscreen")
                {
                    WindowUtilities.LaunchFullScreenGrab();
                    handledArgument = true;
                }
                else if (e.Args[i] == "EditText")
                {
                    EditTextWindow manipulateTextWindow = new EditTextWindow();
                    manipulateTextWindow.Show();
                    handledArgument = true;
                }
                else if (File.Exists(e.Args[i]))
                {
                    EditTextWindow manipulateTextWindow = new EditTextWindow();
                    manipulateTextWindow.OpenThisPath(e.Args[i]);
                    manipulateTextWindow.Show();
                    handledArgument = true;
                }
            }

            if (!handledArgument)
            {
                if (Settings.Default.FirstRun)
                {
                    FirstRunWindow frw = new FirstRunWindow();
                    frw.Show();

                    Settings.Default.FirstRun = false;
                    Settings.Default.Save();
                }
                else
                {
                    switch (Settings.Default.DefaultLaunch)
                    {
                    case "Fullscreen":
                        WindowUtilities.LaunchFullScreenGrab();
                        break;

                    case "GrabFrame":
                        GrabFrame gf = new GrabFrame();
                        gf.Show();
                        break;

                    case "EditText":
                        EditTextWindow manipulateTextWindow = new EditTextWindow();
                        manipulateTextWindow.Show();
                        break;

                    default:
                        EditTextWindow editTextWindow = new EditTextWindow();
                        editTextWindow.Show();
                        break;
                    }
                }
            }
        }
コード例 #2
0
ファイル: App.xaml.cs プロジェクト: peterdur/Text-Grab
        protected void NormalLaunch()
        {
            // base.OnActivated(e);

            var allScreens = Screen.AllScreens;
            var allWindows = System.Windows.Application.Current.Windows;

            foreach (Screen screen in allScreens)
            {
                bool screenHasWindow = true;

                foreach (Window window in allWindows)
                {
                    System.Drawing.Point windowCenter =
                        new System.Drawing.Point(
                            (int)(window.Left + (window.Width / 2)),
                            (int)(window.Top + (window.Height / 2)));
                    screenHasWindow = screen.Bounds.Contains(windowCenter);
                }

                if (allWindows.Count < 1)
                {
                    screenHasWindow = false;
                }

                if (screenHasWindow == false)
                {
                    MainWindow mw = new MainWindow();
                    mw.WindowStartupLocation = WindowStartupLocation.Manual;
                    mw.Width  = 200;
                    mw.Height = 200;

                    mw.WindowState = WindowState.Normal;

                    if (screen.WorkingArea.Left >= 0)
                    {
                        mw.Left = screen.WorkingArea.Left;
                    }
                    else
                    {
                        mw.Left = screen.WorkingArea.Left + (screen.WorkingArea.Width / 2);
                    }

                    if (screen.WorkingArea.Top >= 0)
                    {
                        mw.Top = screen.WorkingArea.Top;
                    }
                    else
                    {
                        mw.Top = screen.WorkingArea.Top + (screen.WorkingArea.Height / 2);
                    }

                    mw.Show();
                }
            }

            if (Settings.Default.FirstRun)
            {
                FirstRunWindow frw = new FirstRunWindow();
                frw.Show();

                Settings.Default.FirstRun = false;
                Settings.Default.Save();
            }
        }