private static bool EnumWindows(IntPtr hWnd, int lParam) { if (!WinApi.IsWindowVisible(hWnd)) return true; var title = new StringBuilder(256); WinApi.GetWindowText(hWnd, title, 256); if (string.IsNullOrEmpty(title.ToString())) { return true; } if (title.Length != 0 || (title.Length == 0 & hWnd != WinApi.statusbar)) { var window = new SystemWindow(hWnd); // IsTopmostWindow为的是去掉start窗口 if (!window.IsTopmostWindow()) { if (IsValidateProcess(window.Process.ProcessName)) { openingWindows.Add(window); } else if (window.IsAltTabWindow()) { openingWindows.Add(window); } } } return true; }
/// <summary> /// Check whether this window is a descendant of <c>ancestor</c> /// </summary> /// <param name="ancestor">The suspected ancestor</param> /// <returns>If this is really an ancestor</returns> public bool IsDescendantOf(SystemWindow ancestor) { return IsChild(ancestor._hwnd, _hwnd); }
/// <summary> /// Returns all child windows that match the given predicate. /// </summary> /// <param name="directOnly">Whether to include only direct children (no descendants)</param> /// <param name="predicate">The predicate to filter.</param> /// <returns>The list of child windows.</returns> public SystemWindow[] FilterDescendantWindows(bool directOnly, Predicate<SystemWindow> predicate) { List<SystemWindow> wnds = new List<SystemWindow>(); EnumChildWindows(_hwnd, delegate(IntPtr hwnd, IntPtr lParam) { SystemWindow tmp = new SystemWindow(hwnd); bool add = true; if (directOnly) { add = tmp.Parent._hwnd == _hwnd; } if (add && predicate(tmp)) wnds.Add(tmp); return 1; }, new IntPtr(0)); return wnds.ToArray(); }
private static int getArea(SystemWindow sw) { RECT rr = sw.Rectangle; return rr.Height * rr.Width; }
/// <summary> /// Returns all toplevel windows that match the given predicate. /// </summary> /// <param name="predicate">The predicate to filter.</param> /// <returns>The filtered toplevel windows</returns> public static SystemWindow[] FilterToplevelWindows(Predicate<SystemWindow> predicate) { List<SystemWindow> wnds = new List<SystemWindow>(); EnumWindows(new EnumWindowsProc(delegate(IntPtr hwnd, IntPtr lParam) { SystemWindow tmp = new SystemWindow(hwnd); if (predicate(tmp)) wnds.Add(tmp); return 1; }), new IntPtr(0)); return wnds.ToArray(); }
/// public bool Equals(SystemWindow sw) { if ((object)sw == null) { return false; } return _hwnd == sw._hwnd; }