4

e.g, Is the user playing a movie full screen, or looking at powerpoint in full screen mode?

I could have sworn I saw a IsFullScreenInteractive API before, but can't find it now

prakash
  • 58,901
  • 25
  • 93
  • 115

4 Answers4

5

Vista indeed has an API pretty much exactly for this purpose - it's called SHQueryUserNotificationState.

ilmcuts
  • 313
  • 3
  • 9
  • 1
    This is perfect! It even goes into more reasons, than those listed in the original question, of why you wouldn't want to show a notification. – Thiru Jun 14 '12 at 00:58
  • This is nice, but doesn't work for situations where the non-main monitor is full-screen. – HaveSpacesuit Feb 06 '18 at 15:42
5

Here's how I've solved this problem:

using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(IsForegroundWwindowFullScreen());
        }

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

        [DllImport("user32.dll")]
        static extern int GetSystemMetrics(int smIndex);

        public const int SM_CXSCREEN = 0;
        public const int SM_CYSCREEN = 1;

        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool GetWindowRect(IntPtr hWnd, out W32RECT lpRect);

        [StructLayout(LayoutKind.Sequential)]
        public struct W32RECT
        {
            public int Left;
            public int Top;
            public int Right;
            public int Bottom;
        }

        public static bool IsForegroundWwindowFullScreen()
        {
            int scrX = GetSystemMetrics(SM_CXSCREEN),
                scrY = GetSystemMetrics(SM_CYSCREEN);

            IntPtr handle = GetForegroundWindow();
            if (handle == IntPtr.Zero) return false;

            W32RECT wRect;
            if (!GetWindowRect(handle, out wRect)) return false;

            return scrX == (wRect.Right - wRect.Left) && scrY == (wRect.Bottom - wRect.Top);
        }
    }
}
Pop Catalin
  • 61,751
  • 23
  • 87
  • 115
  • I didn't see no comments... BTW, the double WW gave me a headache ... it might be because of the beers, don't worry... :) – hannson Jul 31 '09 at 07:10
  • Is there some event to handle that accomplishes the same thing? this solution is fairly clunky when an application needs to constantly check whether something has entered fullscreen or not. – xandermonkey May 23 '17 at 20:20
2

Use GetForegroundWindow to get a handle to the window the user is working with. GetClientRect will give the dimensions of the active part of the window sans borders; use ClientToScreen to convert the rectangle to monitor coordinates.

Call MonitorFromRect or MonitorFromWindow to get the monitor that the window is in. Use GetMonitorInfo to get the coordinates of the monitor.

Compare the two rectangles - if the window rectangle completely covers the monitor rectangle, it's a full screen window.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
0

The preferred way of detecting the state of a window is by calling GetWindowPlacement. If you do that in conjunction with GetForegroundWindow, you can easily check if the user sees a fullscreen window or not.