Ejemplo n.º 1
0
        /// <summary>
        ///     Check if a Windows Store App (WinRT) is visible
        /// </summary>
        /// <param name="windowBounds"></param>
        /// <returns>true if an app, covering the supplied rect, is visisble</returns>
        public static bool AppVisible(NativeRect windowBounds)
        {
            if (AppVisibility == null)
            {
                return(true);
            }

            foreach (var screen in User32Api.AllDisplays())
            {
                if (screen.Bounds.Contains(windowBounds))
                {
                    if (windowBounds.Equals(screen.Bounds))
                    {
                        // Fullscreen, it's "visible" when AppVisibilityOnMonitor says yes
                        // Although it might be the other App, this is not "very" important
                        var rect    = screen.Bounds;
                        var monitor = User32Api.MonitorFromRect(ref rect, MonitorFrom.DefaultToNearest);
                        if (monitor != IntPtr.Zero)
                        {
                            var monitorAppVisibility = AppVisibility.ComObject.GetAppVisibilityOnMonitor(monitor);
                            if (monitorAppVisibility == MonitorAppVisibility.MAV_APP_VISIBLE)
                            {
                                return(true);
                            }
                        }
                    }
                    else
                    {
                        // Is only partly on the screen, when this happens the app is allways visible!
                        return(true);
                    }
                }
            }
            return(false);
        }