gpt4 book ai didi

windows - 在Windows 10中,我们如何判断一个窗口属于哪个虚拟桌面呢?

转载 作者:可可西里 更新时间:2023-11-01 13:40:42 25 4
gpt4 key购买 nike

关于 Windows 10 及其新的虚拟桌面功能,有没有办法确定特定窗口属于哪个虚拟桌面?还有,哪个虚拟桌面处于事件状态?

可以使用截图工具查看问题。打开该工具并选择一个新建/窗口截图。当您四处移动鼠标时,截图工具突出显示没有窗口的区域,但在另一个虚拟桌面的那个位置有一个窗口。

In this picture, the Snipping Tool is highlighting an empty spot.

截图工具不知道特定窗口在哪个虚拟桌面上。

Here's the same question on MSDN Forums, unanswered, but with lots of additional detail.

抱歉,我的状态不够高,无法插入图片或包含更多链接。

最佳答案

Windows SDK Support Team Blog发布了 C# demo to switch Desktops通过IVirtualDesktopManager :

    [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("a5cd92ff-29be-454c-8d04-d82879fb3f1b")]
[System.Security.SuppressUnmanagedCodeSecurity]
public 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")]
public class CVirtualDesktopManager
{

}
public class VirtualDesktopManager
{
public VirtualDesktopManager()
{
cmanager = new CVirtualDesktopManager();
manager = (IVirtualDesktopManager)cmanager;
}
~VirtualDesktopManager()
{
manager = null;
cmanager = null;
}
private CVirtualDesktopManager cmanager = null;
private IVirtualDesktopManager manager;

public bool IsWindowOnCurrentVirtualDesktop(IntPtr TopLevelWindow)
{
int result;
int hr;
if ((hr = manager.IsWindowOnCurrentVirtualDesktop(TopLevelWindow, out result)) != 0)
{
Marshal.ThrowExceptionForHR(hr);
}
return result != 0;
}

public Guid GetWindowDesktopId(IntPtr TopLevelWindow)
{
Guid result;
int hr;
if ((hr = manager.GetWindowDesktopId(TopLevelWindow, out result)) != 0)
{
Marshal.ThrowExceptionForHR(hr);
}
return result;
}

public void MoveWindowToDesktop(IntPtr TopLevelWindow, Guid CurrentDesktop)
{
int hr;
if ((hr = manager.MoveWindowToDesktop(TopLevelWindow, CurrentDesktop)) != 0)
{
Marshal.ThrowExceptionForHR(hr);
}
}
}

调用 GetWindowDesktopId 获取桌面 GUID。

关于windows - 在Windows 10中,我们如何判断一个窗口属于哪个虚拟桌面呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27977924/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com