我需要显示最顶层的窗口(系统托盘中的气球),而不会重叠任何全屏窗口.例如,如果用户观看电影时出现我的最顶层窗口,则该窗口不得出现在电影屏幕的顶部.仅当用户关闭其全屏窗口时,窗口才会出现.
现在,我只是这样展示我的窗口:
window.show()
在风格中我打开这些属性:
<Setter Property="Topmost" Value="True" /> <Setter Property="WindowStyle" Value="None" /> <Setter Property="ShowActivated" Value="False" />
如果他看电影或玩游戏,你能帮忙弄清楚如何在不打扰用户的情况下展示最顶层的窗户吗?
解决方法
我不知道对这个wpf的任何内置支持.因此,如果我必须实现这一点,我会发现我的操作系统中的Foreground窗口是全屏运行,然后不要将我的窗口作为全屏启动.
要在OS中获取当前的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以全屏模式运行,则函数返回以下函数.
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();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。