Проверка, находиться ли компьютер в полноэкранном режиме - C#
Формулировка задачи:
Здравствуйте, подскажите, как реализовать функцию, которая бы возвращала значение, находиться ли компьютер в FULL SCREEN режиме на данный момент или нет?
Решение задачи: «Проверка, находиться ли компьютер в полноэкранном режиме»
textual
Листинг программы
class FullSceen
{
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
private static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
private static extern IntPtr GetShellWindow();
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowRect(IntPtr hwnd, out RECT rc);
private IntPtr desktopHandle; //Window handle for the desktop
private IntPtr shellHandle; //Window handle for the shell
//Get the handles for the desktop and shell now.
public bool isfull()
{
desktopHandle = GetDesktopWindow();
shellHandle = GetShellWindow();
bool runningFullScreen = false;
RECT appBounds;
Rectangle screenBounds;
IntPtr hWnd;
//get the dimensions of the active window
hWnd = GetForegroundWindow();
if (hWnd != null && !hWnd.Equals(IntPtr.Zero))
{
//Check we haven't picked up the desktop or the shell
if (!(hWnd.Equals(desktopHandle) || hWnd.Equals(shellHandle)))
{
GetWindowRect(hWnd, out appBounds);
//determine if window is fullscreen
screenBounds = Screen.FromHandle(hWnd).Bounds;
if ((appBounds.Bottom - appBounds.Top) == screenBounds.Height && (appBounds.Right - appBounds.Left) == screenBounds.Width)
{
runningFullScreen = true;
}
}
}
return (runningFullScreen);
}
}