ThrowIfNotSupported() static private méthode

static private ThrowIfNotSupported ( ) : void
Résultat void
        /// <summary>
        /// Returns the virtual desktop that the specified window is located.
        /// </summary>
        public static VirtualDesktop FromHwnd(IntPtr hwnd)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            if (hwnd == IntPtr.Zero)
            {
                return(null);
            }

            IVirtualDesktop desktop;

            try
            {
                var desktopId = ComObjects.VirtualDesktopManager.GetWindowDesktopId(hwnd);
                desktop = ComObjects.VirtualDesktopManagerInternal.FindDesktop(ref desktopId);
            }
            catch (COMException ex)
            {
                if (ex.Match(HResult.REGDB_E_CLASSNOTREG, HResult.TYPE_E_ELEMENTNOTFOUND))
                {
                    return(null);
                }
                throw;
            }
            var wrapper = _wrappers.GetOrAdd(desktop.GetID(), _ => new VirtualDesktop(desktop));

            return(wrapper);
        }
Exemple #2
0
        /// <summary>
        /// Returns the virtual desktop of the specified identifier.
        /// </summary>
        public static VirtualDesktop FromId(Guid desktopId)
        {
            if (desktopId == Guid.Empty)
            {
                throw new ArgumentNullException(nameof(desktopId));
            }

            if (HasMinimalSupport && !IsSupported)
            {
                var wrapper = _wrappers.GetOrAdd(desktopId, _ => new VirtualDesktop(desktopId));
                return(wrapper);
            }
            else
            {
                VirtualDesktopHelper.ThrowIfNotSupported();

                IVirtualDesktop desktop;
                try {
                    desktop = ComObjects.VirtualDesktopManagerInternal.FindDesktop(ref desktopId);
                } catch (COMException ex) when(ex.Match(HResult.TYPE_E_ELEMENTNOTFOUND))
                {
                    return(null);
                }

                var wrapper = _wrappers.GetOrAdd(desktop.GetID(), _ => new VirtualDesktop(desktop));

                return(wrapper);
            }
        }
        public static VirtualDesktop FromComObject(IVirtualDesktop desktop)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            var wrapper = wrappers.GetOrAdd(desktop.GetID(), _ => new VirtualDesktop(desktop));

            return(wrapper);
        }
        public static void UnpinApplication([NotNull] string appId)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            if (ComInterface.VirtualDesktopPinnedApps.IsAppIdPinned(appId))
            {
                ComInterface.VirtualDesktopPinnedApps.UnpinAppID(appId);
            }
        }
        /// <summary>
        /// Creates a virtual desktop.
        /// </summary>
        public static VirtualDesktop Create()
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            var desktop = ComInternal.CreateDesktopW();
            var wrapper = wrappers.GetOrAdd(desktop.GetID(), _ => new VirtualDesktop(desktop));

            return(wrapper);
        }
        public static void UnpinApplication(string appId)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            if (ComObjects.VirtualDesktopPinnedApps.IsAppIdPinned(appId))
            {
                ComObjects.VirtualDesktopPinnedApps.UnpinAppID(appId);
            }
        }
        public static void PinWindow(IntPtr hWnd)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            var view = hWnd.GetApplicationView();

            if (!ComInterface.VirtualDesktopPinnedApps.IsViewPinned(view))
            {
                ComInterface.VirtualDesktopPinnedApps.PinView(view);
            }
        }
        public static void UnpinWindow(IntPtr hWnd)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            var view = hWnd.GetApplicationView();

            if (ComObjects.VirtualDesktopPinnedApps.IsViewPinned(view))
            {
                ComObjects.VirtualDesktopPinnedApps.UnpinView(view);
            }
        }
        public static bool IsPinnedWindow(IntPtr hWnd)
        {
            if (hWnd != IntPtr.Zero)
            {
                VirtualDesktopHelper.ThrowIfNotSupported();

                return(ComObjects.VirtualDesktopPinnedApps.IsViewPinned(hWnd.GetApplicationView()));
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Returns the virtual desktop of the specified identifier.
        /// </summary>
        public static VirtualDesktop FromId(Guid desktopId)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            try
            {
                return(ComInterface.VirtualDesktopManagerInternal.FindDesktop(ref desktopId));
            }
            catch (COMException ex) when(ex.Match(HResult.TYPE_E_ELEMENTNOTFOUND))
            {
                return(null);
            }
        }
        public static string GetAppId(IntPtr hWnd)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            try
            {
                return(hWnd.GetApplicationView().GetAppUserModelId());
            }
            catch (COMException ex) when(ex.Match(HResult.TYPE_E_ELEMENTNOTFOUND))
            {
                return(null);
            }
        }
        /// <summary>
        /// Returns the virtual desktop of the specified identifier.
        /// </summary>
        public static VirtualDesktop FromId(Guid desktopId)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            IVirtualDesktop desktop;

            try
            {
                desktop = ComInternal.FindDesktop(desktopId);
            }
            catch (COMException ex)             //when (ex.Match(HResult.TYPE_E_ELEMENTNOTFOUND))
            {
                return(null);
            }
            var wrapper = wrappers.GetOrAdd(desktop.GetID(), _ => new VirtualDesktop(desktop));

            return(wrapper);
        }
Exemple #13
0
        internal static IEnumerable <VirtualDesktop> GetDesktopsInternal()
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            var desktops = ComObjects.VirtualDesktopManagerInternal.GetDesktops();
            var count    = desktops.GetCount();

            for (var i = 0u; i < count; i++)
            {
                object ppvObject;
                desktops.GetAt(i, typeof(IVirtualDesktop).GUID, out ppvObject);

                var desktop = (IVirtualDesktop)ppvObject;
                var wrapper = _wrappers.GetOrAdd(desktop.GetID(), _ => new VirtualDesktop(desktop));

                yield return(wrapper);
            }
        }
        /// <summary>
        /// Returns the virtual desktop that the specified window is located.
        /// </summary>
        public static VirtualDesktop FromHwnd(IntPtr hwnd)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            if (hwnd == IntPtr.Zero)
            {
                return(null);
            }

            try
            {
                var desktopId = ComInterface.VirtualDesktopManager.GetWindowDesktopId(hwnd);
                return(ComInterface.VirtualDesktopManagerInternal.FindDesktop(ref desktopId));
            }
            catch (COMException ex) when(ex.Match(HResult.REGDB_E_CLASSNOTREG, HResult.TYPE_E_ELEMENTNOTFOUND))
            {
                return(null);
            }
        }
        /// <summary>
        /// Creates a virtual desktop.
        /// </summary>
        public static VirtualDesktop Create()
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            return(ComInterface.VirtualDesktopManagerInternal.CreateDesktopW());
        }
        /// <summary>
        /// Returns all the virtual desktops of currently valid.
        /// </summary>
        /// <returns></returns>
        public static VirtualDesktop[] GetDesktops()
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            return(ComInterface.VirtualDesktopManagerInternal.GetDesktops().ToArray());
        }
        /// <summary>
        /// Returns all the virtual desktops of currently valid.
        /// </summary>
        /// <returns></returns>
        public static VirtualDesktop[] GetDesktops()
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            return(GetDesktopsInternal().ToArray());
        }
        public static bool IsPinnedWindow(IntPtr hWnd)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            return(ComInterface.VirtualDesktopPinnedApps.IsViewPinned(hWnd.GetApplicationView()));
        }
        public static bool IsPinnedApplication([NotNull] string appId)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            return(ComInterface.VirtualDesktopPinnedApps.IsAppIdPinned(appId));
        }
        public static bool IsPinnedApplication(string appId)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            return(ComObjects.VirtualDesktopPinnedApps.IsAppIdPinned(appId));
        }