Is there a way to check if another program is running in full screen mode

As in the question. Can I see if someone else is working, program, full screen?

Full screen mode means that the entire screen is shaded, perhaps working in a different video mode than the desktop.

+4
source share
2 answers

Here is the code that does this. You want to take care of the multiscreen case, especially in applications like 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); } 
+7
source

Made some changes. The code below does not falsely return true when the taskbar is hidden or on the second screen. Tested under 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; } } 
0
source

All Articles