4

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

我可以发誓我以前看到过 IsFullScreenInteractive API,但现在找不到

4

4 回答 4

5

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

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);
        }
    }
}
于 2009-01-30T12:38:44.607 回答
4

Vista 确实有一个几乎完全用于此目的的 API - 它称为SHQueryUserNotificationState

于 2009-07-31T07:04:50.500 回答
2

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

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

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

于 2008-10-14T20:32:02.630 回答
0

检测窗口状态的首选方法是调用GetWindowPlacement。如果与 GetForegroundWindow 一起执行此操作,则可以轻松检查用户是否看到全屏窗口。

于 2009-07-12T19:38:18.757 回答