Example #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);
                    }
                }
            }
        }
        protected new Form GetOrCreateForm(Control control)
        {
            bool resizeRequired = !Windows.ContainsKey(control);
            Form form           = base.GetOrCreateForm(control);

            form.ShowInTaskbar = (_owner == null);
            if (resizeRequired)
            {
                form.ClientSize = control.Size;
            }
            return(form);
        }
 /// <summary>
 /// Registers the window for the specified Task
 /// </summary>
 public void RegisterWindow <T_>(T window) where T_ : IWindow, new()
 {
     if (Windows.ContainsKey(window) && Windows[window] != null)
     {
         Windows[window].Add(new T_());
     }
     else
     {
         Windows[window] = new HashSet <IWindow> {
             new T_()
         }
     };
     WindowStates.Add(window, false);
 }
Example #4
0
 private WindowMock FindOwnWindow(IWindow iWindow)
 {
     if (iWindow is WindowMock window)
     {
         var rawId = window.Id.RawId;
         if (Windows.ContainsKey(rawId))
         {
             return(Windows[rawId]);
         }
         else
         {
             return(null);
         }
     }
     return(null);
 }
Example #5
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;
            }
        }
        internal void FireEvent(API.ShellEvents nEvent, int lExtraInfo)
        {
            if (_MonitorWindowEvents)
            {
                //int pId;
                //int tId;
                switch (nEvent)
                {
                case API.ShellEvents.HSHELL_WINDOWCREATED:
                    if (!Windows.ContainsKey(lExtraInfo.ToString()))
                    {
                        Window window = new Window(new IntPtr(lExtraInfo));
                        Windows.Add(window.Handle.ToString(), window);
                        if (WindowCreated != null)
                        {
                            WindowCreated(window);
                        }
                    }

                    break;

                case API.ShellEvents.HSHELL_WINDOWDESTROYED:
                    if (Windows.ContainsKey(lExtraInfo.ToString()))
                    {
                        if (WindowDestroyed != null)
                        {
                            WindowDestroyed(Windows[lExtraInfo.ToString()]);
                        }
                        Windows.Remove(lExtraInfo.ToString());
                    }

                    break;

                case API.ShellEvents.HSHELL_ACTIVATESHELLWINDOW:
                    if (ShellWindowActivated != null)
                    {
                        ShellWindowActivated();
                    }

                    break;

                case API.ShellEvents.HSHELL_WINDOWACTIVATED:
                    if (!ShellHandles.Contains("," + lExtraInfo + ","))
                    {
                        ActiveWindowHandle = new IntPtr(lExtraInfo);
                        if (WindowActivated != null)
                        {
                            WindowActivated(Windows[lExtraInfo.ToString()]);
                        }
                    }

                    break;

                case API.ShellEvents.HSHELL_TASKMAN:
                    if (TaskManActivated != null)
                    {
                        TaskManActivated(lExtraInfo);
                    }

                    break;

                default:
                    break;
                }
            }
        }