Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to check to see if another program is running full screen

Tags:

c#

fullscreen

Just like the question says. Can I see if someone else, program, is running full screen?

Full screen means that the entire screen is obscured, possibly running in a different video mode than the desktop.

like image 350
QueueHammer Avatar asked Sep 18 '10 23:09

QueueHammer


People also ask

How do you know if a game is fullscreen?

If you ALT + TAB out of the game and the game minimizes, then its fullscreen (requires another application window in the background). If it stays open, then its borderless window.

How can I see the whole window?

On a Windows computer, you can set Google Chrome, Internet Explorer, Microsoft Edge, or Mozilla Firefox to full-screen mode, hiding the toolbars and address bar by pressing the F11 key.

Is used to display full screen program area?

In a browser on a Windows computer, you can enter fullscreen mode by pressing F11 . The key or method for entering fullscreen mode may vary in other programs.


2 Answers

Here is some code that does it. You want to take care about the multi screen case, especially with applications like Powerpoint

    [StructLayout(LayoutKind.Sequential)]
    private struct RECT
    {
        public int left;
        public int top;
        public int right;
        public int bottom;
    }

    [DllImport("user32.dll")]
    private static extern bool GetWindowRect(HandleRef hWnd, [In, Out] ref RECT rect);

    [DllImport("user32.dll")]
    private static extern IntPtr GetForegroundWindow();

    public static bool IsForegroundFullScreen()
    {
        return IsForegroundFullScreen(null);
    }

    public static bool IsForegroundFullScreen(Screen screen)
    {
        if (screen == null)
        {
            screen = Screen.PrimaryScreen;
        }
        RECT rect = new RECT();
        GetWindowRect(new HandleRef(null, GetForegroundWindow()), ref rect);
        return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top).Contains(screen.Bounds); 
    }
like image 108
Simon Mourier Avatar answered Oct 24 '22 08:10

Simon Mourier


I did some modifications. With the code below it doesn't falsely return true when taskbar is hidden or on a second screen. Tested under Win 7.

    [StructLayout(LayoutKind.Sequential)]
    public struct RECT
    {
        public int left;
        public int top;
        public int right;
        public int bottom;
    }

    [DllImport("user32.dll", SetLastError = true)]
    public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);

    [DllImport("user32.dll")]
    private static extern bool GetWindowRect(HandleRef hWnd, [In, Out] ref RECT rect);

    [DllImport("user32.dll")]
    private static extern IntPtr GetForegroundWindow();

    public static bool IsForegroundFullScreen()
    {
        return IsForegroundFullScreen(null);
    }


    public static bool IsForegroundFullScreen(System.Windows.Forms.Screen screen)
    {

        if (screen == null)
        {
            screen = System.Windows.Forms.Screen.PrimaryScreen;
        }
        RECT rect = new RECT();
        IntPtr hWnd = (IntPtr)GetForegroundWindow();


        GetWindowRect(new HandleRef(null, hWnd), ref rect);

        /* in case you want the process name:
        uint procId = 0;
        GetWindowThreadProcessId(hWnd, out procId);
        var proc = System.Diagnostics.Process.GetProcessById((int)procId);
        Console.WriteLine(proc.ProcessName);
        */


        if (screen.Bounds.Width == (rect.right - rect.left) && screen.Bounds.Height == (rect.bottom - rect.top))
        {
            Console.WriteLine("Fullscreen!")
            return true;
        }
        else {
            Console.WriteLine("Nope, :-(");
            return false;
        }


    }
like image 28
ARN Avatar answered Oct 24 '22 08:10

ARN