做了个小工具,检测当前系统中有没有正在运行的全屏应用,自己不用写,网上也还挺不好找,最后找了一段,有效
代码是这样:
[StructLayout(LayoutKind.Sequential)] public struct RECT { public int left; public int top; public int right; public int bottom; } [DllImport("user32.dll", SetLastError = true)] public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); [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(); IntPtr hWnd = (IntPtr)GetForegroundWindow(); GetWindowRect(new HandleRef(null, hWnd), ref rect); if (screen.Bounds.Width == (rect.right - rect.left) && screen.Bounds.Height == (rect.bottom - rect.top)) { Console.WriteLine("Fullscreen"); return true; } else { Console.WriteLine("No Fullscreen"); return false; } }
使用:
bool isFullScreen = IsForegroundFullScreen(null);