/// <summary> /// Determines if a window is a task window or not /// </summary> /// <param name="handle">Handle to the window</param> /// <returns>True if it is a task window</returns> public static bool IsTaskWindow(IntPtr handle) { if (Win32.User32.User32API.IsWindowVisible(handle) && WindowsTaskManager.GetWindowText(handle).Length > 0) { System.Text.StringBuilder buf = new System.Text.StringBuilder(255); Rectangle rWin = GetWindowBounds(handle); //if (rWin.Width > 0 && rWin.Height > 0 && rWin.IntersectsWith(System.Windows.Forms.Screen.PrimaryScreen.Bounds)) // the intersect command hides minimized windows if (rWin.Width > 0 && rWin.Height > 0) { if (HideMinimizedWindows) { if (!rWin.IntersectsWith(System.Windows.Forms.Screen.PrimaryScreen.Bounds)) { return(false); } } Win32.User32.User32API.GetClassName(handle, buf, buf.MaxCapacity); if (buf.ToString() != "Progman" && buf.ToString() != "SysListView32") { return(true); } } } return(false); }
/// <summary> /// Tells if a window is in the provided ExcludedWindowList /// </summary> /// <param name="handle">Handle to the window to verify</param> /// <param name="excludedWindowsList">List with the excluded windows</param> /// <returns>True if window belongs in the excluded window list</returns> public static bool IsTaskExcluded(IntPtr handle, ExcludedWindow[] excludedWindowsList) { if (excludedWindowsList == null) { return(false); } foreach (ExcludedWindow Excluded in excludedWindowsList) { //System.Diagnostics.Debug.WriteLine(Excluded.ProcessName.ToLower()+" and "+System.IO.Path.GetFileName(WindowsTaskManager.GetExecutableName(Handle)).ToLower()); //System.Diagnostics.Debug.WriteLine(Excluded.ClassName+" and "+WindowsTaskManager.GetWindowClass(Handle)); //if(Excluded.ProcessName.ToLower()==System.IO.Path.GetFileName(WindowsTaskManager.GetExecutableName(handle)).ToLower() if (String.Compare(Excluded.ProcessName, System.IO.Path.GetFileName(WindowsTaskManager.GetExecutableName(handle)), true, System.Globalization.CultureInfo.InvariantCulture) == 0 && Excluded.ClassName == WindowsTaskManager.GetWindowClass(handle)) { return(true); } } return(false); }
/// <summary> /// Gets the handles to all windows in their appearance order /// </summary> /// <param name="excludedWindowsList">List with all the excluded windows</param> /// <returns>Returns handles to all open windows</returns> public static IntPtr[] GetWindowHandles(ExcludedWindow[] excludedWindowsList) { // count how many windows are there int i = 0; IntPtr Handle = Win32.User32.User32API.GetForegroundWindow(); do { if (WindowsTaskManager.IsTaskWindow(Handle) && !IsTaskExcluded(Handle, excludedWindowsList)) { i++; } Handle = Win32.User32.User32API.GetWindow(Handle, Win32.User32.GetWindowCommand.Next); } while (Handle != IntPtr.Zero); // if no tasks are available if (i == 0) { return(null); } // actually catalog them IntPtr[] ItemRegistry = new IntPtr[i]; int a = 0; Handle = Win32.User32.User32API.GetForegroundWindow(); do { if (WindowsTaskManager.IsTaskWindow(Handle) && !IsTaskExcluded(Handle, excludedWindowsList)) { ItemRegistry[a] = Handle; a++; } Handle = Win32.User32.User32API.GetWindow(Handle, Win32.User32.GetWindowCommand.Next); } while(Handle != IntPtr.Zero); return(ItemRegistry); }