/// <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);
        }
示例#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);
        }
        /// <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([NotNull] string appId)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            if (ComInterface.VirtualDesktopPinnedApps.IsAppIdPinned(appId))
            {
                ComInterface.VirtualDesktopPinnedApps.UnpinAppID(appId);
            }
        }
        public static void UnpinApplication(string appId)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

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

            var view = hWnd.GetApplicationView();

            if (ComObjects.VirtualDesktopPinnedApps.IsViewPinned(view))
            {
                ComObjects.VirtualDesktopPinnedApps.UnpinView(view);
            }
        }
        public static void PinWindow(IntPtr hWnd)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            var view = hWnd.GetApplicationView();

            if (!ComInterface.VirtualDesktopPinnedApps.IsViewPinned(view))
            {
                ComInterface.VirtualDesktopPinnedApps.PinView(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);
            }
        }
示例#12
0
        /// <summary>
        /// Returns ID of the virtual desktop, where specified window is located.
        /// </summary>
        public static Guid?IdFromHwnd(IntPtr hwnd)
        {
            VirtualDesktopHelper.ThrowIfNoMinimalSupport();

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

            try {
                return(ComObjects.VirtualDesktopManager.GetWindowDesktopId(hwnd));
            } catch (COMException ex) when(ex.Match(HResult.REGDB_E_CLASSNOTREG, 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);
        }
示例#14
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);
            }
        }
 public static void TogglePin(this Window window)
 {
     VirtualDesktopHelper.TogglePinWindow(window.GetHandle());
 }
        public static bool IsPinnedApplication(string appId)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

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

            return(ComInterface.VirtualDesktopManagerInternal.GetDesktops().ToArray());
        }
        /// <summary>
        /// Creates a virtual desktop.
        /// </summary>
        public static VirtualDesktop Create()
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            return(ComInterface.VirtualDesktopManagerInternal.CreateDesktopW());
        }
        public static bool IsPinnedWindow(IntPtr hWnd)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

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

            return(GetDesktopsInternal().ToArray());
        }
        public static bool IsPinnedApplication([NotNull] string appId)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            return(ComInterface.VirtualDesktopPinnedApps.IsAppIdPinned(appId));
        }
示例#23
0
 public static bool IsCurrentVirtualDesktop(this Form form)
 {
     return(VirtualDesktopHelper.IsCurrentVirtualDesktop(form.Handle));
 }
 public static void Unpin(this Window window)
 {
     VirtualDesktopHelper.UnpinWindow(window.GetHandle());
 }
示例#25
0
 /// <summary>
 /// Move this window to specified virtual desktop.
 /// </summary>
 public static void MoveToDesktop(this Window window, VirtualDesktop virtualDesktop)
 {
     VirtualDesktopHelper.MoveToDesktop(window.GetHandle(), virtualDesktop);
 }
示例#26
0
 /// <summary>
 /// Determines whether the window is located over the virtual desktop that current displayed.
 /// </summary>
 public static bool IsCurrentVirtualDesktop(this Window window)
 {
     return(VirtualDesktopHelper.IsCurrentVirtualDesktop(window.GetHandle()));
 }
示例#27
0
 public static void MoveToDesktop(this Form form, VirtualDesktop virtualDesktop)
 {
     VirtualDesktopHelper.MoveToDesktop(form.Handle, virtualDesktop);
 }
 public static bool IsPinned(this Window window)
 {
     return(VirtualDesktopHelper.IsPinnedWindow(window.GetHandle()));
 }