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

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

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

这是一些代码。 您需要关注多屏幕情况,尤其是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); } 

我做了一些修改。 使用下面的代码,当隐藏任务栏或在第二个屏幕上时,它不会错误地返回true。 在Win 7下测试。

  [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(System.Windows.Forms.Screen screen) { if (screen == null) { screen = System.Windows.Forms.Screen.PrimaryScreen; } RECT rect = new RECT(); IntPtr hWnd = (IntPtr)GetForegroundWindow(); GetWindowRect(new HandleRef(null, hWnd), ref rect); /* in case you want the process name: uint procId = 0; GetWindowThreadProcessId(hWnd, out procId); var proc = System.Diagnostics.Process.GetProcessById((int)procId); Console.WriteLine(proc.ProcessName); */ if (screen.Bounds.Width == (rect.right - rect.left) && screen.Bounds.Height == (rect.bottom - rect.top)) { Console.WriteLine("Fullscreen!") return true; } else { Console.WriteLine("Nope, :-("); return false; } }