mirror of
https://github.com/kangyu-california/PersistentWindows.git
synced 2025-05-11 13:05:38 +02:00
add VirtualDesktop.cs
This commit is contained in:
parent
d8a6f54756
commit
b84d15ea76
2 changed files with 82 additions and 0 deletions
|
@ -0,0 +1,81 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using PersistentWindows.Common.Diagnostics;
|
||||
|
||||
namespace PersistentWindows.Common
|
||||
{
|
||||
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("a5cd92ff-29be-454c-8d04-d82879fb3f1b")]
|
||||
internal interface IVirtualDesktopManager
|
||||
{
|
||||
[PreserveSig]
|
||||
int IsWindowOnCurrentVirtualDesktop([In] IntPtr TopLevelWindow, [Out] out int OnCurrentDesktop);
|
||||
|
||||
[PreserveSig]
|
||||
int GetWindowDesktopId([In] IntPtr TopLevelWindow, [Out] out Guid CurrentDesktop);
|
||||
|
||||
[PreserveSig]
|
||||
int MoveWindowToDesktop([In] IntPtr TopLevelWindow, [MarshalAs(UnmanagedType.LPStruct)][In] Guid CurrentDesktop);
|
||||
}
|
||||
|
||||
[ComImport, Guid("aa509086-5ca9-4c25-8f95-589d3c07b48a")]
|
||||
internal class CVirtualDesktopManager
|
||||
{
|
||||
}
|
||||
|
||||
public class VirtualDesktop
|
||||
{
|
||||
private static IVirtualDesktopManager _manager = null;
|
||||
|
||||
public VirtualDesktop()
|
||||
{
|
||||
try
|
||||
{
|
||||
_manager = (IVirtualDesktopManager)new CVirtualDesktopManager();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Log.Error("VirtualDesktop feature not supported by OS");
|
||||
}
|
||||
}
|
||||
|
||||
public bool Enabled()
|
||||
{
|
||||
return _manager != null;
|
||||
}
|
||||
|
||||
public bool IsWindowOnCurrentVirtualDesktop(IntPtr TopLevelWindow)
|
||||
{
|
||||
int hr = _manager.IsWindowOnCurrentVirtualDesktop(TopLevelWindow, out int result);
|
||||
if (hr != 0)
|
||||
{
|
||||
//Marshal.ThrowExceptionForHR(hr);
|
||||
Log.Error("IsWindowOnCurrentVirtualDesktop() call failed");
|
||||
}
|
||||
|
||||
return result != 0;
|
||||
}
|
||||
|
||||
public Guid GetWindowDesktopId(IntPtr TopLevelWindow)
|
||||
{
|
||||
int hr = _manager.GetWindowDesktopId(TopLevelWindow, out Guid result);
|
||||
if (hr != 0)
|
||||
{
|
||||
//Marshal.ThrowExceptionForHR(hr);
|
||||
Log.Error("GetWindowDesktopId() call failed");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void MoveWindowToDesktop(IntPtr TopLevelWindow, Guid CurrentDesktop)
|
||||
{
|
||||
int hr = _manager.MoveWindowToDesktop(TopLevelWindow, CurrentDesktop);
|
||||
if (hr != 0)
|
||||
{
|
||||
//Marshal.ThrowExceptionForHR(hr);
|
||||
Log.Error("MoveWindowToDesktop() call failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue