ACAT.Lib.Extension.CommandHandlers.AppWindowManagementHandler.Execute C# (CSharp) Method

Execute() public method

Executes the command
public Execute ( bool &handled ) : bool
handled bool set to true if the command was handled
return bool
        public override bool Execute(ref bool handled)
        {
            handled = true;

            switch (Command)
            {
                case "CmdMaximizeWindow":
                    if (isForegroundWindowSizeable())
                    {
                        Windows.MaximizeWindow(Windows.GetForegroundWindow());
                    }
                    break;

                case "CmdRestoreWindow":
                    if (isForegroundWindowSizeable())
                    {
                        Windows.RestoreWindow(Windows.GetForegroundWindow());
                    }
                    break;

                case "CmdCloseWindow":
                    var info = WindowActivityMonitor.GetForegroundWindowInfo();
                    WindowHighlight win = null;
                    if (info.FgHwnd != IntPtr.Zero)
                    {
                        win = new WindowHighlight(info.FgHwnd, Dispatcher.Scanner.Form);
                    }

                    if (DialogUtils.ConfirmScanner(null, ACATExtension.Resources.CloseTheHighlightedWindow))
                    {
                        AgentManager.Instance.Keyboard.Send(Keys.LMenu, Keys.F4);
                    }

                    if (win != null)
                    {
                        win.Dispose();
                    }

                    break;

                case "CmdMoveWindow":
                    if (!isForegroundWindowSizeable())
                    {
                        break;
                    }

                    Dispatcher.Scanner.Form.Invoke(new MethodInvoker(delegate()
                    {
                        const int delay = 500;

                        Context.AppAgentMgr.Keyboard.Send(Keys.LMenu, Keys.Space);
                        Thread.Sleep(delay);
                        Context.AppAgentMgr.Keyboard.Send(Keys.M);

                        Form form = Context.AppPanelManager.CreatePanel("WindowMoveResizeScannerForm");
                        if (form != null)
                        {
                            form.Text = "Move Window";
                            Context.AppPanelManager.ShowDialog(form as IPanel);
                        }
                    }));
                    break;

                case "CmdSizeWindow":
                    if (!isForegroundWindowSizeable())
                    {
                        break;
                    }

                    Dispatcher.Scanner.Form.Invoke(new MethodInvoker(delegate()
                    {
                        int delay = 500;

                        Context.AppAgentMgr.Keyboard.Send(Keys.LMenu, Keys.Space);
                        Thread.Sleep(delay);
                        Context.AppAgentMgr.Keyboard.Send(Keys.S);

                        Form form = Context.AppPanelManager.CreatePanel("WindowMoveResizeScannerForm");
                        if (form != null)
                        {
                            form.Text = "Resize Window";
                            Context.AppPanelManager.ShowDialog(form as IPanel);
                        }
                    }));
                    break;

                case "CmdMinimizeWindow":
                    if (isForegroundWindowSizeable())
                    {
                        Windows.MinimizeWindow(User32Interop.GetForegroundWindow());
                    }
                    break;

                case "CmdMaxRestoreWindow":
                    if (!isForegroundWindowSizeable())
                    {
                        break;
                    }

                    IntPtr handle = User32Interop.GetForegroundWindow();
                    if (Windows.IsMaximized(handle))
                    {
                        Windows.RestoreWindow(handle);
                    }
                    else
                    {
                        Windows.MaximizeWindow(handle);
                    }

                    break;

                case "CmdParitalMaximizeWindow":
                case "CmdThreeFourthMaximizeWindow":
                    if (!isForegroundWindowSizeable())
                    {
                        break;
                    }

                    Dispatcher.Scanner.Form.Invoke(new MethodInvoker(delegate()
                    {
                        Windows.SetForegroundWindowSizePercent(Context.AppWindowPosition,
                                                                Common.AppPreferences.WindowMaximizeSizePercent);
                    }));
                    break;

                case "CmdMaximizePartialMaximizeToggle":
                case "CmdMaximizeThreeFourthToggle":
                    if (!isForegroundWindowSizeable())
                    {
                        break;
                    }

                    Windows.ToggleFgWindowMaximizeAndPartialMaximize(Context.AppWindowPosition,
                                                                Common.AppPreferences.WindowMaximizeSizePercent);
                    break;

                default:
                    handled = false;
                    break;
            }

            return true;
        }