How to check whether another app is minimized or not?

c#

Solution

[DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);

    private struct WINDOWPLACEMENT {
        public int length;
        public int flags;
        public int showCmd;
        public System.Drawing.Point ptMinPosition;
        public System.Drawing.Point ptMaxPosition;
        public System.Drawing.Rectangle rcNormalPosition;
    }

if (p.MainWindowHandle != IntPtr.Zero) {
    if (p.MainWindowTitle.Contains("Notepad")) {
        WINDOWPLACEMENT placement = new WINDOWPLACEMENT();
        GetWindowPlacement(p.MainWindowHandle, ref placement);
        switch (placement.showCmd) {
           case 1:
             Console.WriteLine("Normal");
             break;
           case 2:
             Console.WriteLine("Minimized");
             break;
           case 3:
             Console.WriteLine("Maximized");
             break;
        }
    }                   
}

Problem

How can I check whether another application is minimized or not? For instance in a loop like this: ``` foreach(Process p in processes) { // Does a process have a window? // If so, is it minimized, normal, or maximized } ```

Original source