示例#1
0
 static void InitializeWindows()
 {
     WinApp = new System.Windows.Application();
     WinApp.Run(MainWindow = new Projekt.View.Okno());
 }
示例#2
0
            public ProgramContextMenu(Program program)
            {
                AutoAccept = new MenuItem("Auto accept", CheckAndSave)
                {
                    Checked = Settings.Default.AutoAccept
                };
                AutoLock = new MenuItem("Auto lock", CheckAndSave)
                {
                    Checked = Settings.Default.AutoLock
                };
                AutoPick = new MenuItem("Auto pick", (sender, args) =>
                {
                    var window = program.autoPickFormWPF;

                    void OpenNewAutoPick(System.Windows.Application application)
                    => application.Dispatcher.Invoke(() =>
                    {
                        window                  = new AutoPickWPF();
                        window.Closed          += (o, eventArgs) => program.autoPickFormWPF = null;
                        program.autoPickFormWPF = window;
                        window.Show();
                    });

                    if (window == null)
                    {
                        var app = System.Windows.Application.Current;
                        if (app == null)
                        {
                            var thread = new Thread(() =>
                            {
                                app = new System.Windows.Application
                                {
                                    ShutdownMode = ShutdownMode.OnExplicitShutdown
                                };
                                OpenNewAutoPick(app);
                                app.Run();
                            });

                            thread.SetApartmentState(ApartmentState.STA);
                            thread.Start();
                        }
                        else
                        {
                            OpenNewAutoPick(app);
                        }
                    }
                    else
                    {
                        program.autoPickFormWPF.Dispatcher.Invoke(() =>
                        {
                            if (!window.IsVisible)
                            {
                                window.Show();
                            }

                            if (window.WindowState == WindowState.Minimized)
                            {
                                window.WindowState = WindowState.Normal;
                            }

                            window.Activate();
                            window.Topmost = true;                              // important
                            window.Topmost = false;                             // important
                            window.Focus();                                     // important
                        });
                    }

                    //if (program.autoPickForm == null)
                    //{
                    //	program.autoPickForm = new AutoPickForm();
                    //	program.autoPickForm.FormClosed += (o, eventArgs) => program.autoPickForm = null;
                    //	var thread = new Thread(() => Application.Run(program.autoPickForm));
                    //	thread.SetApartmentState(ApartmentState.STA);
                    //	thread.Start();
                    //}
                    //else
                    //{
                    //	program.autoPickForm.BringToFront();
                    //}
                });
#if DEBUG
                AutoPick.PerformClick();
#endif
                var rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

                string currentRegValue = (string)rkApp?.GetValue(nameof(LolAutoAccept));
                if (currentRegValue != null && currentRegValue != Application.ExecutablePath)
                {
                    rkApp.SetValue(nameof(LolAutoAccept), Application.ExecutablePath);
                }
                AutoLoad = new MenuItem("Autoload on startup",
                                        (sender, args) =>
                {
                    ((MenuItem)sender).Checked = !((MenuItem)sender).Checked;
                    if (((MenuItem)sender).Checked)
                    {
                        //string src = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                        //string dest = "C:\\temp\\" + System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName;
                        //System.IO.File.Copy(src, dest);

                        // Add the value in the registry so that the application runs at startup
                        rkApp?.SetValue(nameof(LolAutoAccept), Application.ExecutablePath);
                    }
                    else
                    {
                        // Remove the value from the registry so that the application doesn't start
                        rkApp?.DeleteValue(nameof(LolAutoAccept), false);
                    }
                })
                {
                    Checked = currentRegValue != null
                };

                CapturePattern = new MenuItem("CapturePattern (for dev only)",
                                              (sender, args) =>
                {
                    program.patternCaptureForm             = new PatterCaptureForm();
                    program.patternCaptureForm.FormClosed += (o, eventArgs) => program.patternCaptureForm = null;
                    var thread = new Thread(() => Application.Run(program.patternCaptureForm));
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                });

                SearchMatchingPatternSize = new MenuItem("SearchMatchingPatternSize (for dev only)",
                                                         (sender, args) =>
                {
                    var thread = new Thread(() => Application.Run(new SearchMatchingSizeForm()));
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                });

                MenuItems.AddRange(new[]
                {
                    AutoAccept, AutoLock, Divider1, AutoPick, Divider2, AutoLoad, Divider3, CapturePattern, SearchMatchingPatternSize, Divider4, Exit
                });
            }