gpt4 book ai didi

c# - 在 C#/.Net 中创建/切换桌面

转载 作者:行者123 更新时间:2023-11-30 17:18:45 25 4
gpt4 key购买 nike

我目前正在使用 CreateDesktop native C 函数并在我的 C# 代码中调用它来创建和切换桌面。有没有办法使用 Process 类或任何 c#/.Net 类来做到这一点?

这是我现在在类里面用于桌面切换的示例代码。

    [Flags]
public enum AccessRight : uint
{
DESKTOP_READOBJECTS = 0x00000001,
DESKTOP_CREATEWINDOW = 0x00000002,
DESKTOP_CREATEMENU = 0x00000004,
DESKTOP_HOOKCONTROL = 0x00000008,
DESKTOP_JOURNALRECORD = 0x00000010,
DESKTOP_JOURNALPLAYBACK = 0x00000020,
DESKTOP_ENUMERATE = 0x00000040,
DESKTOP_WRITEOBJECTS = 0x00000080,
DESKTOP_SWITCHDESKTOP = 0x00000100,

GENERIC_ALL = (DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU |
DESKTOP_HOOKCONTROL | DESKTOP_JOURNALRECORD | DESKTOP_JOURNALPLAYBACK |
DESKTOP_ENUMERATE | DESKTOP_WRITEOBJECTS | DESKTOP_SWITCHDESKTOP)
};

[Flags]
public enum AccountHook
{
Allow = 1,
Disallow = 0
};

public enum HandleInheritance
{
Inherit,
None
};

[StructLayout(LayoutKind.Sequential)]
public struct SecAttrib
{
public int nLength;
public IntPtr lpSecurityDescriptor;
public int bInheritHandle;
}

[DllImport("user32.dll")]
public static extern IntPtr OpenDesktop(string lpszDesktop,
uint dwFlags,
bool fInherit,
uint dwDesiredAccess);

[DllImport("user32.dll")]
public static extern bool SwitchDesktop(IntPtr hDesktop);

[DllImport("user32.dll")]
public static extern IntPtr CreateDesktop(string lpszDesktop,
IntPtr lpszDevice,
IntPtr pDevmode,
int dwFlags,
uint dwDesiredAccess,
IntPtr lpsa);

[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr OpenInputDesktop(uint dwFlags, bool fInherit,
uint dwDesiredAccess);



[DllImport("user32.dll", EntryPoint = "CloseDesktop", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CloseDesktop(IntPtr handle);

最佳答案

.net framework 中没有内置桌面切换类/方法。

这里是 Desktop Switching使用 native Windows API 的示例。

如果有任何用于桌面切换的 .net 框架类/方法,他们将使用/包装与您的示例或我提到的 codeproject 中的示例相同的 API。

这里是另一个例子,方法略有不同:Multiple desktop support in Windows

关于c# - 在 C#/.Net 中创建/切换桌面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5484912/

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