是否有一个Vista的API来检测桌面是否全屏运行?

例如,用户正在全屏播放电影,还是在全屏模式下查看幻灯片?

我可以发誓之前,我看到一个IsFullScreenInteractive API,但现在找不到它

以下是我解决这个问题的方法:

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); } } } 

Vista的确有一个非常准确的API,叫做SHQueryUserNotificationState 。

使用GetForegroundWindow获取用户正在处理的窗口的句柄。 GetClientRect将给出窗口sans边框活动部分的尺寸; 使用ClientToScreen将矩形转换为监视坐标。

调用MonitorFromRect或MonitorFromWindow获取窗口所在的监视器。使用GetMonitorInfo获取监视器的坐标。

比较两个矩形 – 如果窗口矩形完全覆盖了监视矩形,则是全屏窗口。

我相信这可能会奏效,但是我认为,他们发布了一个实际的API调用告诉你的状态。

检测窗口状态的首选方法是调用GetWindowPlacement 。 如果与GetForegroundWindow结合使用,则可以轻松检查用户是否看到全屏窗口。