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 を使用します。

2 つの四角形を比較します。ウィンドウの四角形がモニターの四角形を完全に覆っている場合、それはフル スクリーン ウィンドウです。

于 2008-10-14T20:32:02.630 に答える