示例#1
5
        public DesktopInfo()
        {
            using(var searcher = new ManagementObjectSearcher("SELECT UserName FROM Win32_ComputerSystem"))
            {
                using(var collection = searcher.Get())
                {
                    var s = ((string)collection.Cast<ManagementBaseObject>().First()["UserName"]).Split('\\');
                    if(s.Length > 1)
                        Username = s.LastOrDefault();
                    else
                        Username = s.FirstOrDefault();
                }
            }
            _Users_DesktopPath = @"c:\users\" + Username + @"\desktop\";
            InputMouseEvent = Desktop_Sharing_Shared.Mouse.PInvoke.SendMouseEvent;
            InputKeyEvent = Desktop_Sharing_Shared.Keyboard.PInvoke.KeyEvent;

            m_hCurWinsta = new StationHandle(PInvoke.GetProcessWindowStation());
            if(m_hCurWinsta.IsInvalid)
            {

                var er = new Win32Exception(Marshal.GetLastWin32Error());

                throw er;
            }

            m_hWinsta = new StationHandle(PInvoke.OpenWindowStation("winsta0", false,
                ACCESS_MASK.WINSTA_ENUMDESKTOPS |
                ACCESS_MASK.WINSTA_READATTRIBUTES |
                ACCESS_MASK.WINSTA_ACCESSCLIPBOARD |
                ACCESS_MASK.WINSTA_CREATEDESKTOP |
                ACCESS_MASK.WINSTA_WRITEATTRIBUTES |
                ACCESS_MASK.WINSTA_ACCESSGLOBALATOMS |
                ACCESS_MASK.WINSTA_EXITWINDOWS |
                ACCESS_MASK.WINSTA_ENUMERATE |
                ACCESS_MASK.WINSTA_READSCREEN));
            if(m_hWinsta.IsInvalid)
            {

                var er = new Win32Exception(Marshal.GetLastWin32Error());

                throw er;
            }

            if(!PInvoke.SetProcessWindowStation(m_hWinsta.Handle))
            {

                var er = new Win32Exception(Marshal.GetLastWin32Error());

                throw er;
            }
            m_hDesk = new DesktopHandle(PInvoke.OpenDesktop("default", 0, false,
                    ACCESS_MASK.DESKTOP_CREATEMENU |
                    ACCESS_MASK.DESKTOP_CREATEWINDOW |
                    ACCESS_MASK.DESKTOP_ENUMERATE |
                    ACCESS_MASK.DESKTOP_HOOKCONTROL |
                    ACCESS_MASK.DESKTOP_JOURNALPLAYBACK |
                    ACCESS_MASK.DESKTOP_JOURNALRECORD |
                    ACCESS_MASK.DESKTOP_READOBJECTS |
                    ACCESS_MASK.DESKTOP_SWITCHDESKTOP |
                    ACCESS_MASK.DESKTOP_WRITEOBJECTS));
            if(m_hDesk.IsInvalid)
            {

                var er = new Win32Exception(Marshal.GetLastWin32Error());

                throw er;
            }
            if(!PInvoke.SetThreadDesktop(m_hDesk.Handle))
            {

                var er = new Win32Exception(Marshal.GetLastWin32Error());

                throw er;
            }
            Current_Desktop = GetDesktop(m_hDesk);
        }
示例#2
0
        public MainForm()
        {
            InitializeComponent();
            var file = File.OpenWrite("test.txt");

            file.Position = file.Length;

            var process = System.Diagnostics.Process.GetCurrentProcess();

            using (StreamWriter sw = new StreamWriter(file))
                sw.WriteLine(User32.GetThreadDesktop(User32.GetCurrentThreadId()).ToString() + " " + User32.GetCurrentThreadId().ToString());


            hotkeys = new List <Hotkey>();
            DesktopManager.Desktops = new List <Desktop>();

            MainDesktopHandle = User32.GetDesktopWindow();
            CurrentDesktop    = new Desktop("Default", MainDesktopHandle, CreateGraphics(), MainDesktopHandle);
            CurrentDesktop    = startDesktop;
            File.WriteAllText(@"C:\Users\Public\Desktops\mainhandle.txt", MainDesktopHandle.ToString()); //TODO No hardcoded thinks

            GetDesktops();
            comboBox.Items.AddRange(Desktops.ToArray());
            hotkeys.Add(new Hotkey(Handle, hotkeys.Count, (int)KeyModifier.MOD_CONTROL, Keys.O));
        }
示例#3
0
        private void DesktopButton_Click(object sender, EventArgs e)
        {
            startDesktop.Save();


            if (string.IsNullOrWhiteSpace(comboBox.Text))
            {
                return;
            }

            var desk = Desktops.FirstOrDefault(d => d.Name == comboBox.Text);

            if (desk == null)
            {
                desk = new Desktop(comboBox.Text, MainDesktopHandle, CreateGraphics());
                Desktops.Add(desk);
                GetDesktops();
            }

            desktopControl1.Add(CurrentDesktop.Name, CurrentDesktop.TakeScreenshot());
            desk.Show();
            desk.CreateProcess(Path.Combine(Environment.GetEnvironmentVariable("windir"), @"explorer.exe"));
            //desk.CreateProcess(Path.Combine(Environment.GetEnvironmentVariable("windir"), @"explorer.exe"));
            CurrentDesktop = desk;
        }
示例#4
0
        public bool SwitchDesktop(Desktops dname)
        {
            f.WriteLine("Switch TO" + Enum.GetName(dname.GetType(), dname));
            var desktop = new DesktopHandle(PInvoke.OpenDesktop(Enum.GetName(dname.GetType(), dname), 0, false,
                                                                ACCESS_MASK.DESKTOP_CREATEMENU | ACCESS_MASK.DESKTOP_CREATEWINDOW |
                                                                ACCESS_MASK.DESKTOP_ENUMERATE | ACCESS_MASK.DESKTOP_HOOKCONTROL |
                                                                ACCESS_MASK.DESKTOP_WRITEOBJECTS | ACCESS_MASK.DESKTOP_READOBJECTS |
                                                                ACCESS_MASK.DESKTOP_SWITCHDESKTOP | ACCESS_MASK.GENERIC_WRITE));

            f.WriteLine("Switch Invalid" + desktop.IsInvalid);
            if (desktop.IsInvalid)
            {
                return(false);
            }
            if (!PInvoke.SetThreadDesktop(desktop.Handle))
            {
                f.WriteLine("Switch failed" + Marshal.GetLastWin32Error());
                desktop.Dispose();
                return(false);
            }
            m_hDesk.Dispose();
            m_hDesk         = desktop;
            Current_Desktop = dname;
            f.WriteLine("Switch Success" + dname);
            return(true);
        }
示例#5
0
        public static void NewDesktopSwitch(string name, string handle)
        {
            var desk = Desktops.FirstOrDefault(x => x.Name == name);

            desk.DesktopHelper.DesktopHandle = new IntPtr(int.Parse(handle));
            Task.Run(() => { MessageBox.Show(handle.ToString()); });
        }
示例#6
0
        public static void Switch(string name)
        {
            startDesktop.Save();

            if (string.IsNullOrWhiteSpace(name))
            {
                return;
            }

            var desk = Desktops.FirstOrDefault(d => d.Name == name);

            if (desk == null)
            {
                desk = new Desktop(name, MainDesktopHandle);
                Desktops.Add(desk);
            }
            //var list = Process.GetProcesses().Where(x => x.ProcessName.ToLower().Contains("explorer")).ToList();
            //list.ForEach(x => x.Kill());
            desk.Show();
            CurrentDesktop = desk;

            if (MainService.Clients.Contains(name))
            {
                return;
            }
            desk.CreateProcess(Path.Combine(Environment.GetEnvironmentVariable("windir"), @"explorer.exe"));
            desk.CreateProcess(@"..\..\..\\TestTop.UI\bin\Debug\TestTop.UI.exe");
        }
示例#7
0
        public Task <IDesktop> GetNext(IDesktop desktop)
        {
            var index = Desktops.IndexOf(desktop);

            index++;
            index = index % Desktops.Count;
            return(Task.FromResult(Desktops[index]));
        }
示例#8
0
 private void Add(Desktop desktop)
 {
     Desktops.Add(desktop);
     if (DesktopsByName.ContainsKey(desktop.Id))
     {
         Desktops.Remove(DesktopsByName[desktop.Id]);
     }
     DesktopsByName[desktop.Id] = desktop;
 }
示例#9
0
        public Task <IDesktop> GetPrev(IDesktop desktop)
        {
            var index = Desktops.IndexOf(desktop);

            if (index < 0)
            {
                index = Desktops.Count - 1;
            }
            else
            {
                index += Desktops.Count;
                index--;
                index = index % Desktops.Count;
            }
            return(Task.FromResult(Desktops[index]));
        }
示例#10
0
        public bool SwitchDesktop(Desktops dname)
        {
            var desktop = new DesktopHandle(PInvoke.OpenDesktop(Enum.GetName(dname.GetType(), dname), 0, false,
                                                                ACCESS_MASK.DESKTOP_CREATEMENU | ACCESS_MASK.DESKTOP_CREATEWINDOW |
                                                                ACCESS_MASK.DESKTOP_ENUMERATE | ACCESS_MASK.DESKTOP_HOOKCONTROL |
                                                                ACCESS_MASK.DESKTOP_WRITEOBJECTS | ACCESS_MASK.DESKTOP_READOBJECTS |
                                                                ACCESS_MASK.DESKTOP_SWITCHDESKTOP | ACCESS_MASK.GENERIC_WRITE));

            if (desktop.IsInvalid)
            {
                return(false);
            }
            if (!PInvoke.SetThreadDesktop(desktop.Handle))
            {
                desktop.Dispose();
                return(false);
            }
            m_hDesk.Dispose();
            m_hDesk         = desktop;
            Current_Desktop = dname;
            return(true);
        }
示例#11
0
 /// <summary>
 /// Добавляет рабочий стол в репозиторий
 /// </summary>
 /// <param name="desktop"></param>
 public void AddDesktop(DesktopModel desktop)
 {
     Desktops.Add(desktop);
 }
示例#12
0
 private static bool DesktopEnumProc(string lpszDesktop, IntPtr lParam)
 {
     Desktops.Add(new Desktop(lpszDesktop, MainDesktopHandle));;
     return(true);
 }
示例#13
0
        public bool SwitchDesktop(Desktops dname)
        {
            var desktop = new DesktopHandle(PInvoke.OpenDesktop(Enum.GetName(dname.GetType(), dname), 0, false,
                 ACCESS_MASK.DESKTOP_CREATEMENU | ACCESS_MASK.DESKTOP_CREATEWINDOW |
                 ACCESS_MASK.DESKTOP_ENUMERATE | ACCESS_MASK.DESKTOP_HOOKCONTROL |
                 ACCESS_MASK.DESKTOP_WRITEOBJECTS | ACCESS_MASK.DESKTOP_READOBJECTS |
                 ACCESS_MASK.DESKTOP_SWITCHDESKTOP | ACCESS_MASK.GENERIC_WRITE));

            if(desktop.IsInvalid)
                return false;
            if(!PInvoke.SetThreadDesktop(desktop.Handle))
            {
                desktop.Dispose();
                return false;
            }
            m_hDesk.Dispose();
            m_hDesk = desktop;
            Current_Desktop = dname;
            return true;
        }
示例#14
0
 private bool DesktopEnumProc(string lpszDesktop, IntPtr lParam)
 {
     Desktops.Add(new Desktop(lpszDesktop, MainDesktopHandle, CreateGraphics()));;
     return(true);
 }
示例#15
0
        public DesktopInfo()
        {
            using (var searcher = new ManagementObjectSearcher("SELECT UserName FROM Win32_ComputerSystem"))
            {
                using (var collection = searcher.Get())
                {
                    var s = ((string)collection.Cast <ManagementBaseObject>().First()["UserName"]).Split('\\');
                    if (s.Length > 1)
                    {
                        Username = s.LastOrDefault();
                    }
                    else
                    {
                        Username = s.FirstOrDefault();
                    }
                }
            }
            _Users_DesktopPath = @"c:\users\" + Username + @"\desktop\";
            InputMouseEvent    = Desktop_Sharing_Shared.Mouse.PInvoke.SendMouseEvent;
            InputKeyEvent      = Desktop_Sharing_Shared.Keyboard.PInvoke.KeyEvent;


            m_hCurWinsta = new StationHandle(PInvoke.GetProcessWindowStation());
            if (m_hCurWinsta.IsInvalid)
            {
                var er = new Win32Exception(Marshal.GetLastWin32Error());

                throw er;
            }

            m_hWinsta = new StationHandle(PInvoke.OpenWindowStation("winsta0", false,
                                                                    ACCESS_MASK.WINSTA_ENUMDESKTOPS |
                                                                    ACCESS_MASK.WINSTA_READATTRIBUTES |
                                                                    ACCESS_MASK.WINSTA_ACCESSCLIPBOARD |
                                                                    ACCESS_MASK.WINSTA_CREATEDESKTOP |
                                                                    ACCESS_MASK.WINSTA_WRITEATTRIBUTES |
                                                                    ACCESS_MASK.WINSTA_ACCESSGLOBALATOMS |
                                                                    ACCESS_MASK.WINSTA_EXITWINDOWS |
                                                                    ACCESS_MASK.WINSTA_ENUMERATE |
                                                                    ACCESS_MASK.WINSTA_READSCREEN));
            if (m_hWinsta.IsInvalid)
            {
                var er = new Win32Exception(Marshal.GetLastWin32Error());

                throw er;
            }

            if (!PInvoke.SetProcessWindowStation(m_hWinsta.Handle))
            {
                var er = new Win32Exception(Marshal.GetLastWin32Error());

                throw er;
            }
            m_hDesk = new DesktopHandle(PInvoke.OpenDesktop("default", 0, false,
                                                            ACCESS_MASK.DESKTOP_CREATEMENU |
                                                            ACCESS_MASK.DESKTOP_CREATEWINDOW |
                                                            ACCESS_MASK.DESKTOP_ENUMERATE |
                                                            ACCESS_MASK.DESKTOP_HOOKCONTROL |
                                                            ACCESS_MASK.DESKTOP_JOURNALPLAYBACK |
                                                            ACCESS_MASK.DESKTOP_JOURNALRECORD |
                                                            ACCESS_MASK.DESKTOP_READOBJECTS |
                                                            ACCESS_MASK.DESKTOP_SWITCHDESKTOP |
                                                            ACCESS_MASK.DESKTOP_WRITEOBJECTS));
            if (m_hDesk.IsInvalid)
            {
                var er = new Win32Exception(Marshal.GetLastWin32Error());

                throw er;
            }
            if (!PInvoke.SetThreadDesktop(m_hDesk.Handle))
            {
                var er = new Win32Exception(Marshal.GetLastWin32Error());

                throw er;
            }
            Current_Desktop = GetDesktop(m_hDesk);
        }
示例#16
0
 /// <summary>
 /// Удаляет последний рабочий стол из репозитория
 /// </summary>
 public void DeleteLastDesktop()
 {
     Desktops.RemoveAt(Desktops.Count - 1);
 }
示例#17
0
 /// <summary>
 /// Возвращает рабочий стол из репозитория по индексу
 /// </summary>
 /// <param name="index"></param>
 /// <returns></returns>
 public DesktopModel GetDesktop(Int16 index)
 {
     return(Desktops.ElementAt(index));
 }