示例#1
0
        public void AddWindow(DesktopWindow desktopWindow)
        {
            Pair <string, string> configurableFilter = ConfigurableFilters.FirstOrDefault(f => f.Item1 == desktopWindow.AppName);

            if (!Windows.ContainsKey(desktopWindow.GetDesktopMonitor()))
            {
                Windows.Add(desktopWindow.GetDesktopMonitor(), new ObservableCollection <DesktopWindow>());
                Windows[desktopWindow.GetDesktopMonitor()].CollectionChanged += Windows_CollectionChanged;
            }

            if (FixedFilters.All(s => !desktopWindow.AppName.StartsWith(s)) &&
                desktopWindow.AppName != String.Empty &&
                !Windows[desktopWindow.GetDesktopMonitor()].Contains(desktopWindow))
            {
                if (configurableFilter.Equals(null))
                {
                    Windows[desktopWindow.GetDesktopMonitor()].Add(desktopWindow);
                }
                else
                {
                    if (configurableFilter.Item2 != "*" && configurableFilter.Item2 != desktopWindow.ClassName)
                    {
                        Windows[desktopWindow.GetDesktopMonitor()].Add(desktopWindow);
                    }
                }
            }
        }
示例#2
0
        public void GetWindows()
        {
            User32.EnumWindowsProc filterDesktopWindows = delegate(HWND windowHandle, IntPtr lparam)
            {
                DesktopWindow desktopWindow = new DesktopWindow(windowHandle);

                if (desktopWindow.IsRuntimePresent())
                {
                    User32.ShowWindow(windowHandle, ShowWindowCommand.SW_RESTORE);
                    desktopWindow.GetInfo();

                    if (Windows.ContainsKey(desktopWindow.GetDesktopMonitor()))
                    {
                        if (!Windows[desktopWindow.GetDesktopMonitor()].Contains(desktopWindow))
                        {
                            AddWindow(desktopWindow);
                        }
                    }
                    else
                    {
                        Windows.Add(
                            desktopWindow.GetDesktopMonitor(),
                            new ObservableCollection <DesktopWindow>(new DesktopWindow[] { })
                            );
                        AddWindow(desktopWindow);
                    }
                }
                return(true);
            };

            User32.EnumWindows(filterDesktopWindows, IntPtr.Zero);

            foreach (var desktopMonitor in Windows)
            {
                Windows[desktopMonitor.Key].CollectionChanged += Windows_CollectionChanged;
            }
        }
示例#3
0
 private void Windows_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (e.Action.Equals(NotifyCollectionChangedAction.Remove))
     {
         DesktopWindow desktopWindow = (DesktopWindow)e.OldItems[0];
         Draw(desktopWindow.GetDesktopMonitor());
         Changed.Invoke(this, "add");
     }
     else if (e.Action.Equals(NotifyCollectionChangedAction.Add))
     {
         DesktopWindow desktopWindow = (DesktopWindow)e.NewItems[0];
         Draw(desktopWindow.GetDesktopMonitor());
         Changed.Invoke(this, "remove");
     }
 }
示例#4
0
        public void MoveWindowPreviousScreen(DesktopWindow window)
        {
            List <Pair <VirtualDesktop, HMONITOR> > desktopMonitors = Windows.Keys.Where(dM => dM.Item1.ToString() == VirtualDesktop.Current.ToString()).ToList();
            int currentMonitorIndex = desktopMonitors.IndexOf(window.GetDesktopMonitor());
            int maxIndex            = desktopMonitors.Count - 1;

            if (currentMonitorIndex == 0)
            {
                RemoveWindow(window);
                window.MonitorHandle = desktopMonitors[maxIndex].Item2;
                AddWindow(window);
            }
            else
            {
                RemoveWindow(window);
                window.MonitorHandle = desktopMonitors[--currentMonitorIndex].Item2;
                AddWindow(window);
            }
        }
示例#5
0
 public void RemoveWindow(DesktopWindow desktopWindow)
 {
     Windows[desktopWindow.GetDesktopMonitor()].Remove(desktopWindow);
 }