예제 #1
0
        /// <summary>
        /// Executes the command
        /// </summary>
        /// <param name="handled">set to true if the command was handled</param>
        /// <returns>true on success</returns>
        public override bool Execute(ref bool handled)
        {
            handled = true;

            IntPtr fgHandle = Windows.GetForegroundWindow();

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

            case "CmdRestoreWindow":
                if (isWindowSizeable(fgHandle))
                {
                    Windows.RestoreWindow(fgHandle);
                }
                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, R.GetString("CloseHighlightedWindow")))
                {
                    AgentManager.Instance.Keyboard.Send(Keys.LMenu, Keys.F4);
                }

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

                break;

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

                Dispatcher.Scanner.Form.Invoke(new MethodInvoker(delegate
                {
                    Form form = Context.AppPanelManager.CreatePanel("WindowMoveResizeScannerForm");
                    if (form != null)
                    {
                        form.Text = R.GetString("MoveWindow");

                        var extension = form as IExtension;
                        if (extension != null)
                        {
                            extension.GetInvoker().SetValue("MoveWindow", true);
                        }

                        Context.AppPanelManager.ShowDialog(form as IPanel);
                    }
                }));
                break;

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

                Dispatcher.Scanner.Form.Invoke(new MethodInvoker(delegate
                {
                    Form form = Context.AppPanelManager.CreatePanel("WindowMoveResizeScannerForm");
                    if (form != null)
                    {
                        form.Text = R.GetString("ResizeWindow");

                        var extension = form as IExtension;
                        if (extension != null)
                        {
                            extension.GetInvoker().SetValue("ResizeWindow", true);
                        }

                        Context.AppPanelManager.ShowDialog(form as IPanel);
                    }
                }));
                break;

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

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

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

                break;

            case "CmdSnapWindow":
                if (!isWindowSizeable(fgHandle))
                {
                    break;
                }

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

            case "CmdSnapWindowToggle":
                if (!isWindowSizeable(fgHandle))
                {
                    break;
                }

                Windows.ToggleSnapForegroundWindow(Context.AppWindowPosition,
                                                   Common.AppPreferences.WindowSnapSizePercent);
                break;

            default:
                handled = false;
                break;
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Executes the command
        /// </summary>
        /// <param name="handled">set to true if the command was handled</param>
        /// <returns>true on success</returns>
        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, "Close the highlighted window?"))
                {
                    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);
        }