Проверка, находиться ли компьютер в полноэкранном режиме - C#

Узнай цену своей работы

Формулировка задачи:

Здравствуйте, подскажите, как реализовать функцию, которая бы возвращала значение, находиться ли компьютер в FULL SCREEN режиме на данный момент или нет?

Решение задачи: «Проверка, находиться ли компьютер в полноэкранном режиме»

textual
Листинг программы
  1.    class FullSceen
  2.     {
  3.         [StructLayout(LayoutKind.Sequential)]
  4.         public struct RECT
  5.         {
  6.             public int Left;
  7.             public int Top;
  8.             public int Right;
  9.             public int Bottom;
  10.         }
  11.         [DllImport("user32.dll")]
  12.         private static extern IntPtr GetForegroundWindow();
  13.         [DllImport("user32.dll")]
  14.         private static extern IntPtr GetDesktopWindow();
  15.         [DllImport("user32.dll")]
  16.         private static extern IntPtr GetShellWindow();
  17.         [DllImport("user32.dll", SetLastError = true)]
  18.         private static extern int GetWindowRect(IntPtr hwnd, out RECT rc);
  19.         private IntPtr desktopHandle; //Window handle for the desktop
  20.         private IntPtr shellHandle; //Window handle for the shell
  21.         //Get the handles for the desktop and shell now.
  22.         public bool isfull()
  23.         {
  24.             desktopHandle = GetDesktopWindow();
  25.             shellHandle = GetShellWindow();
  26.  
  27.             bool runningFullScreen = false;
  28.             RECT appBounds;
  29.             Rectangle screenBounds;
  30.             IntPtr hWnd;
  31.  
  32.             //get the dimensions of the active window
  33.             hWnd = GetForegroundWindow();
  34.             if (hWnd != null && !hWnd.Equals(IntPtr.Zero))
  35.             {
  36.                 //Check we haven't picked up the desktop or the shell
  37.                 if (!(hWnd.Equals(desktopHandle) || hWnd.Equals(shellHandle)))
  38.                 {
  39.                     GetWindowRect(hWnd, out appBounds);
  40.                     //determine if window is fullscreen
  41.                     screenBounds = Screen.FromHandle(hWnd).Bounds;
  42.                     if ((appBounds.Bottom - appBounds.Top) == screenBounds.Height && (appBounds.Right - appBounds.Left) == screenBounds.Width)
  43.                     {
  44.                         runningFullScreen = true;
  45.                     }
  46.                 }
  47.             }
  48.  
  49.             return (runningFullScreen);
  50.         }
  51.     }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

11   голосов , оценка 4.182 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы