/// <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);
            }
        }
コード例 #3
0
        public static VirtualDesktop FromComObject(IVirtualDesktop desktop)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

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

            return(wrapper);
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        public static void UnpinApplication([NotNull] string appId)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            if (ComInterface.VirtualDesktopPinnedApps.IsAppIdPinned(appId))
            {
                ComInterface.VirtualDesktopPinnedApps.UnpinAppID(appId);
            }
        }
コード例 #6
0
        public static void UnpinApplication(string appId)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            if (ComObjects.VirtualDesktopPinnedApps.IsAppIdPinned(appId))
            {
                ComObjects.VirtualDesktopPinnedApps.UnpinAppID(appId);
            }
        }
コード例 #7
0
        public static void UnpinWindow(IntPtr hWnd)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            var view = hWnd.GetApplicationView();

            if (ComObjects.VirtualDesktopPinnedApps.IsViewPinned(view))
            {
                ComObjects.VirtualDesktopPinnedApps.UnpinView(view);
            }
        }
コード例 #8
0
        public static void PinWindow(IntPtr hWnd)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            var view = hWnd.GetApplicationView();

            if (!ComInterface.VirtualDesktopPinnedApps.IsViewPinned(view))
            {
                ComInterface.VirtualDesktopPinnedApps.PinView(view);
            }
        }
コード例 #9
0
        public static bool IsPinnedWindow(IntPtr hWnd)
        {
            if (hWnd != IntPtr.Zero)
            {
                VirtualDesktopHelper.ThrowIfNotSupported();

                return(ComObjects.VirtualDesktopPinnedApps.IsViewPinned(hWnd.GetApplicationView()));
            }
            else
            {
                return(false);
            }
        }
コード例 #10
0
        /// <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);
            }
        }
コード例 #11
0
        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);
            }
        }
コード例 #13
0
        /// <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);
            }
        }
コード例 #15
0
        /// <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);
            }
        }
コード例 #16
0
 public static void TogglePin(this Window window)
 {
     VirtualDesktopHelper.TogglePinWindow(window.GetHandle());
 }
コード例 #17
0
        public static bool IsPinnedApplication(string appId)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

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

            return(ComInterface.VirtualDesktopManagerInternal.GetDesktops().ToArray());
        }
コード例 #19
0
        /// <summary>
        /// Creates a virtual desktop.
        /// </summary>
        public static VirtualDesktop Create()
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

            return(ComInterface.VirtualDesktopManagerInternal.CreateDesktopW());
        }
コード例 #20
0
        public static bool IsPinnedWindow(IntPtr hWnd)
        {
            VirtualDesktopHelper.ThrowIfNotSupported();

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

            return(GetDesktopsInternal().ToArray());
        }
コード例 #22
0
        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));
 }
コード例 #24
0
 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);
 }
コード例 #28
0
 public static bool IsPinned(this Window window)
 {
     return(VirtualDesktopHelper.IsPinnedWindow(window.GetHandle()));
 }