public void UpdateFrom(WindowHandle p_windowHandle) { WindowHandleExtensions.WINDOWPLACEMENT placement = new WindowHandleExtensions.WINDOWPLACEMENT(); p_windowHandle.GetWindowPlacement(ref placement); // TODO: Look into how 'snapped' windows are handled (i.e. those that are // maximised in one dimension only. The width/height don't seem // to reflect this. XPos = placement.rcNormalPosition.left; YPos = placement.rcNormalPosition.top; Width = placement.rcNormalPosition.right - XPos; Height = placement.rcNormalPosition.bottom - YPos; switch (placement.showCmd) { case WindowHandleExtensions.WindowShowStyle.Maximize: Status = WindowStatus.Maximised; break; case WindowHandleExtensions.WindowShowStyle.ShowMinimized: Status = WindowStatus.Minimised; break; default: Status = WindowStatus.Located; break; } }
static public bool IsWindowOnScreen(WindowHandle p_handle, Screen p_screen) { WindowHandleExtensions.WINDOWPLACEMENT placement = new WindowHandleExtensions.WINDOWPLACEMENT(); p_handle.GetWindowPlacement(ref placement); /* Work out where the mid-point of the window is. The screen on which the midpoint resides will be * the one on which the window maximises */ int width = placement.rcNormalPosition.right - placement.rcNormalPosition.left; int height = placement.rcNormalPosition.bottom - placement.rcNormalPosition.top; int midx = placement.rcNormalPosition.left + (width / 2); int midy = placement.rcNormalPosition.top + (height / 2); Point midPoint = new Point(midx, midy); /* Is the mid-point on the specified screen? */ return(p_screen.WorkingArea.Contains(midPoint)); }
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); }