Detecting full screen mode in Windows

hWnd = GetForegroundWindow();
RECT appBounds;
RECT rc;
GetWindowRect(GetDesktopWindow(), &rc);

Then check if that windows isn't desktop or shell. Simple if instruction.

if(hWnd =! GetDesktopWindow() && hWnd != GetShellWindow())
{
    GetWindowRect(hWnd, &appBounds);
    // Now you just have to compare rc to appBounds
}

This is written without testing.


A full implementation of Hooch's answer:

bool isFullscreen(HWND window)
{
    RECT a, b;
    GetWindowRect(window, &a);
    GetWindowRect(GetDesktopWindow(), &b);
    return (a.left   == b.left  &&
            a.top    == b.top   &&
            a.right  == b.right &&
            a.bottom == b.bottom);
}

Hooch's and ens' answers actually don't work on a multiple monitor system. That's because

The rectangle of the desktop window returned by GetWindowRect or GetClientRect is always equal to the rectangle of the primary monitor, for compatibility with existing applications.

See https://docs.microsoft.com/en-us/windows/desktop/gdi/multiple-monitor-system-metrics for reference.

The above means that if the window is fullscreen on a monitor that's not the primary monitor of the system, the coordinates (which are relative to the virtual screen) are completely different from the coordinates of the desktop window.

I fixed this with the following function:

bool isFullscreen(HWND windowHandle)
{
    MONITORINFO monitorInfo = { 0 };
    monitorInfo.cbSize = sizeof(MONITORINFO);
    GetMonitorInfo(MonitorFromWindow(windowHandle, MONITOR_DEFAULTTOPRIMARY), &monitorInfo);

    RECT windowRect;
    GetWindowRect(windowHandle, &windowRect);

    return windowRect.left == monitorInfo.rcMonitor.left
        && windowRect.right == monitorInfo.rcMonitor.right
        && windowRect.top == monitorInfo.rcMonitor.top
        && windowRect.bottom == monitorInfo.rcMonitor.bottom;
}

All other answers are rather hackish.

Windows Vista, Windows 7 and up support SHQueryUserNotificationState():

QUERY_USER_NOTIFICATION_STATE pquns;
SHQueryUserNotificationState(&pquns);

From this "notification state" it is possible to infer the fullscreen state. Basically, when there is an an app running in fullscreen mode, Windows reports a "busy" notification state.

  • QUNS_NOT_PRESENT - not fullscreen (machine locked/screensaver/user switching)
  • QUNS_BUSY – fullscreen (the F11 fullscreen, also all video games I tried use this)
  • QUNS_RUNNING_D3D_FULL_SCREEN – fullscreen (Direct3D application is running in exclusive mode, i.e. fullscreen)
  • QUNS_PRESENTATION_MODE – fullscreen (a special mode for showing presentations, which are fullscreen)
  • QUNS_ACCEPTS_NOTIFICATIONS – not fullscreen
  • QUNS_QUIET_TIME – not fullscreen
  • QUNS_APP – probably fullscreen (not sure: "Introduced in Windows 8. A Windows Store app is running.")

Tags:

C++

Winapi