IEnumerable<Process> processes = Process.GetProcesses() .Where(p => (long)p.MainWindowHandle != 0 && p.MainWindowTitle.Length > 0 && (p.StartInfo.WindowStyle == ProcessWindowStyle.Maximized || p.StartInfo.WindowStyle == ProcessWindowStyle.Normal) && (WindowState.GetWindowState(p.MainWindowHandle) == "Maximized" || WindowState.GetWindowState(p.MainWindowHandle) == "Normal") );
public static class WindowState { private static WINDOWPLACEMENT GetPlacement(IntPtr hwnd) { WINDOWPLACEMENT placement = new WINDOWPLACEMENT(); placement.length = Marshal.SizeOf(placement); GetWindowPlacement(hwnd, ref placement); return placement; } public static string GetWindowState(IntPtr hwnd) { WINDOWPLACEMENT placement = GetPlacement(hwnd); if (placement.showCmd == ShowWindowCommands.Minimized) return "Minimized"; if (placement.showCmd == ShowWindowCommands.Maximized) return "Maximized"; if (placement.showCmd == ShowWindowCommands.Hide) return "Hide"; if (placement.showCmd == ShowWindowCommands.Normal) return "Normal"; return string.Empty; } [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool GetWindowPlacement( IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl); internal enum ShowWindowCommands : int { Hide = 0, Normal = 1, Minimized = 2, Maximized = 3, } [Serializable] [StructLayout(LayoutKind.Sequential)] internal struct WINDOWPLACEMENT { public int length; public int flags; public ShowWindowCommands showCmd; public System.Drawing.Point ptMinPosition; public System.Drawing.Point ptMaxPosition; public System.Drawing.Rectangle rcNormalPosition; } [DllImport("user32.dll")] private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); }
GetWindowState
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)