How to show the topmost window without overlapping fullscreen windows

I need to show the topmost window (a balloon from the system tray) without blocking any windows in full screen mode. For example, if my top window appears when a user watches a movie, the window should not appear on top of the movie screen. A window should only appear when the user closes his full-screen window.

Now I just show my window as follows:

window.show()

In style, I include the following properties:

<Setter Property="Topmost" Value="True" />
<Setter Property="WindowStyle" Value="None" />
<Setter Property="ShowActivated" Value="False" />

Could you help me figure out how to show the topmost window without disturbing the user if he is watching a movie or playing a game?

+4
source share
2 answers

wpf. , , , Foreground , .

Foreground , User32

[DllImport("user32.dll")]
private static extern bool GetWindowRect(HandleRef hWnd, [In, Out] ref RECT rect);

[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();

[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
    public int left;
    public int top;
    public int right;
    public int bottom;
}

System.Windows.Forms System.Drawing, Screen. , ForegroundWindow FullScreen.

    public  bool IsAnyWindowFullScreen()
    {
        RECT rect = new RECT();
        GetWindowRect(new HandleRef(null, GetForegroundWindow()), ref rect);
        return new System.Drawing.Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top).Contains(Screen.PrimaryScreen.Bounds);
    }

 if(!IsAnyWindowFullScreen())
  {
    window.Topmost = true;
  }
  window.Show();
+1

, - , , , ( , , ).

:

  • , , ( , , , ). : , .
  • , ( ), Dispatcher, Topmost = true
0

Source: https://habr.com/ru/post/1545969/


All Articles