Anlegen/Wechsel von Desktop in C#/.Net

Derzeit bin ich über die CreateDesktop native C-Funktion und der Aufruf in meinem C# - code zu erstellen, und wechseln Sie zwischen den desktops. Gibt es irgendeine Möglichkeit, diese mithilfe der Process-Klasse oder c#/.Net-Klasse für diese Angelegenheit?

Dies ist der Beispiel-code, den ich verwende in meiner Klasse jetzt für Desktop-switching.

    [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);
  • Nitpick: die native Windows-API (die CreateDesktop ist ein Teil des) ist eine API in C, nicht C++.
InformationsquelleAutor Ziony | 2011-03-30
Schreibe einen Kommentar