Однако решить эту проблемы вполне возможно.
public partial class Form1: Form
{
[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; //Хэндл рабочего стола
private IntPtr shellHandle; //Хэндл оболочки
public Form1()
{
InitializeComponent();
this.TopMost = true;
//Получаем хэндлы окон оболочки и рабочего стола
desktopHandle = GetDesktopWindow();
shellHandle = GetShellWindow();
}
public bool isThereFullScreenWindow()
{
//Detect if the current app is running in full screen
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;
}
Ну а потом уже все просто:
if (!isThereFullScreenWindow())
this.TopMost = true;
else
this.TopMost = false;
Комментариев нет:
Отправить комментарий