有没有办法检查另一个程序是否全屏运行

时间:2010-09-18 23:38:28

标签: c# fullscreen

就像问题所说的那样。我可以看看其他人,程序是否全屏运行?

全屏意味着整个屏幕都被遮挡,可能以与桌面不同的视频模式运行。

1 个答案:

答案 0 :(得分:9)

这是一些代码。您需要关注多屏幕情况,尤其是Powerpoint

等应用程序
    [StructLayout(LayoutKind.Sequential)]
    private struct RECT
    {
        public int left;
        public int top;
        public int right;
        public int bottom;
    }

    [DllImport("user32.dll")]
    private static extern bool GetWindowRect(HandleRef hWnd, [In, Out] ref RECT rect);

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

    public static bool IsForegroundFullScreen()
    {
        return IsForegroundFullScreen(null);
    }

    public static bool IsForegroundFullScreen(Screen screen)
    {
        if (screen == null)
        {
            screen = Screen.PrimaryScreen;
        }
        RECT rect = new RECT();
        GetWindowRect(new HandleRef(null, GetForegroundWindow()), ref rect);
        return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top).Contains(screen.Bounds); 
    }