Ejemplo n.º 1
0
        static public HashSet <WindowHandle> ApplyLocatedWindow(Config.Top p_config, Config.LocatedWindow p_locatedWindow, HashSet <WindowHandle> p_exclude = null)
        {
            Config.Location loc = p_config.GetLocation(p_locatedWindow.LocationGUID);
            Config.Window   win = p_config.GetWindow(p_locatedWindow.WindowGUID);

            return(ApplyModification(win, loc, p_locatedWindow.AllowMultipleMatches, p_exclude));
        }
Ejemplo n.º 2
0
        static public HashSet <WindowHandle> ApplyModification(Config.Window p_win, Config.Location p_pos, bool p_allowMultiple, HashSet <WindowHandle> p_exclude = null)
        {
            HashSet <WindowHandle>     matches        = new HashSet <WindowHandle>();
            IEnumerable <WindowHandle> currentWindows = GetAllVisibleWindows();

            foreach (WindowHandle windowHandle in currentWindows)
            {
                if (((p_exclude == null) || !(p_exclude.Contains(windowHandle))) && p_win.IsMatchFor(windowHandle))
                {
                    matches.Add(windowHandle);

                    /* If it's a positioned or sized window and it's currently maximised or minimised, then restore it
                     * prior to applying the position/sizing */
                    if (p_pos.XYPosEnabled || p_pos.SizeEnabled || (p_pos.Status == Config.Location.WindowStatus.Maximised))
                    {
                        WindowHandleExtensions.WINDOWPLACEMENT placement = new WindowHandleExtensions.WINDOWPLACEMENT();
                        windowHandle.GetWindowPlacement(ref placement);

                        switch (placement.showCmd)
                        {
                        case WindowHandleExtensions.WindowShowStyle.Maximize:
                        case WindowHandleExtensions.WindowShowStyle.ShowMinimized:
                            windowHandle.RestoreWindow();
                            break;
                        }
                    }

                    if (p_pos.XYPosEnabled)
                    {
                        windowHandle.SetWindowXY(p_pos.XPos, p_pos.YPos);
                    }
                    if (p_pos.SizeEnabled)
                    {
                        windowHandle.SetWindowSize(p_pos.Width, p_pos.Height);
                    }

                    switch (p_pos.Status)
                    {
                    case Config.Location.WindowStatus.Maximised:
                        if (p_pos.MaximiseScreen < Screen.AllScreens.Length)
                        {
                            Screen screen = Screen.AllScreens[p_pos.MaximiseScreen];

                            /* If the window is not on the screen to which it's specified to maximise,
                             * move it */
                            if (!IsWindowOnScreen(windowHandle, screen))
                            {
                                windowHandle.SetWindowXY(screen.WorkingArea.Left,
                                                         screen.WorkingArea.Top);
                                windowHandle.SetWindowSize(screen.WorkingArea.Right - screen.WorkingArea.Left,
                                                           screen.WorkingArea.Bottom - screen.WorkingArea.Top);
                            }
                        }
                        windowHandle.MaximizeWindow();
                        break;

                    case Config.Location.WindowStatus.Minimised:
                        windowHandle.MinimizeWindow();
                        break;

                    case Config.Location.WindowStatus.Located:
                        windowHandle.ShowWindow();
                        break;

                    default:
                        break;
                    }

                    if (!p_allowMultiple)
                    {
                        break;
                    }
                }
            }
            return(matches);
        }