Esempio n. 1
0
        private async Task ManageShown(HWND hWND)
        {
            await Task.Delay(500);

            DesktopWindow desktopWindow = new DesktopWindow(hWND);

            desktopWindow.GetInfo();
            if (desktopWindow.IsRuntimePresent())
            {
                SystrayContext.Logger.Information($"window created");
                DesktopWindowsManager.AddWindow(desktopWindow);
            }
        }
Esempio n. 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;
            }
        }
Esempio n. 3
0
        public void setWindowsHook()
        {
            void WinEventHookAll(User32.HWINEVENTHOOK hWinEventHook, uint winEvent, HWND hwnd, int idObject, int idChild, uint idEventThread, uint dwmsEventTime)
            {
                DesktopWindow desktopWindow = new DesktopWindow(hwnd);

                if (hwnd != HWND.NULL && idObject == User32.ObjectIdentifiers.OBJID_WINDOW && idChild == 0 && desktopWindow.IsRuntimeValuable())
                {
                    switch (winEvent)
                    {
                    case User32.EventConstants.EVENT_OBJECT_SHOW:
                    case User32.EventConstants.EVENT_OBJECT_UNCLOAKED:
                    case User32.EventConstants.EVENT_OBJECT_IME_SHOW:
                    case User32.EventConstants.EVENT_SYSTEM_FOREGROUND:
                        ManageShown(hwnd);
                        break;

                    case User32.EventConstants.EVENT_SYSTEM_MINIMIZEEND:
                        SystrayContext.Logger.Information($"window maximized");
                        desktopWindow.GetInfo();
                        DesktopWindowsManager.AddWindow(desktopWindow);
                        break;

                    case User32.EventConstants.EVENT_SYSTEM_MINIMIZESTART:
                    case User32.EventConstants.EVENT_OBJECT_HIDE:
                    case User32.EventConstants.EVENT_OBJECT_IME_HIDE:
                        SystrayContext.Logger.Information($"window minimized/hide");
                        HMONITOR      monitorHandle = User32.MonitorFromWindow(hwnd, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST);
                        DesktopWindow remove        = DesktopWindowsManager.GetWindowByHandlers(hwnd, monitorHandle, VirtualDesktop.Current);
                        if (remove != null)
                        {
                            DesktopWindowsManager.RemoveWindow(remove);
                        }
                        break;

                    case User32.EventConstants.EVENT_SYSTEM_MOVESIZEEND:
                        SystrayContext.Logger.Information($"window move/size");

                        DesktopWindow  movedWindow1                = DesktopWindowsManager.FindWindow(hwnd);
                        VirtualDesktop movedDesktop1               = VirtualDesktop.FromHwnd(hwnd);
                        HMONITOR       currentMonitor1             = User32.MonitorFromWindow(hwnd, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST);
                        Pair <VirtualDesktop, HMONITOR> movedPair1 = new Pair <VirtualDesktop, HMONITOR>(movedDesktop1, currentMonitor1);

                        DesktopWindow resizedWindow = new DesktopWindow(hwnd);
                        resizedWindow.GetInfo();
                        if (resizedWindow.Info.rcWindow.Size.Equals(movedWindow1.Info.rcWindow.Size))
                        {
                            // Not resized.
                            DesktopWindow  movedWindow2                = DesktopWindowsManager.FindWindow(Control.MousePosition);
                            VirtualDesktop movedDesktop2               = VirtualDesktop.FromHwnd(movedWindow2.Window);
                            HMONITOR       currentMonitor2             = User32.MonitorFromWindow(movedWindow2.Window, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST);
                            Pair <VirtualDesktop, HMONITOR> movedPair2 = new Pair <VirtualDesktop, HMONITOR>(movedDesktop2, currentMonitor2);
                            DesktopWindowsManager.SwapWindows(movedPair1, movedWindow1, movedPair2, movedWindow2);
                            DesktopWindowsManager.Draw(movedPair2);
                        }
                        else
                        {
                            // Resized.
                        }
                        DesktopWindowsManager.Draw(movedPair1);
                        break;

                    default:
                        break;
                    }
                }
            }

            User32.WinEventProc winEventHookAll = new User32.WinEventProc(WinEventHookAll);
            GCHandle            gchCreate       = GCHandle.Alloc(winEventHookAll);

            User32.HWINEVENTHOOK hookAll = User32.SetWinEventHook(User32.EventConstants.EVENT_MIN, User32.EventConstants.EVENT_MAX, HINSTANCE.NULL, winEventHookAll, 0, 0, User32.WINEVENT.WINEVENT_OUTOFCONTEXT | User32.WINEVENT.WINEVENT_SKIPOWNPROCESS);
        }
Esempio n. 4
0
        public void setWindowsHook()
        {
            void WinEventHookAll(User32.HWINEVENTHOOK hWinEventHook, uint winEvent, HWND hwnd, int idObject, int idChild, uint idEventThread, uint dwmsEventTime)
            {
                DesktopWindow desktopWindow = new DesktopWindow(hwnd);

                if (hwnd != HWND.NULL && idObject == User32.ObjectIdentifiers.OBJID_WINDOW && idChild == 0 && desktopWindow.IsRuntimeValuable())
                {
                    switch (winEvent)
                    {
                    case User32.EventConstants.EVENT_OBJECT_SHOW:
                    case User32.EventConstants.EVENT_OBJECT_UNCLOAKED:
                    case User32.EventConstants.EVENT_OBJECT_IME_SHOW:
                    case User32.EventConstants.EVENT_SYSTEM_FOREGROUND:
                        ManageShown(hwnd);
                        break;

                    case User32.EventConstants.EVENT_SYSTEM_MINIMIZEEND:
                        SystrayContext.Logger.Information($"window maximized");
                        desktopWindow.GetInfo();
                        DesktopWindowsManager.AddWindow(desktopWindow);
                        break;

                    case User32.EventConstants.EVENT_SYSTEM_MINIMIZESTART:
                    case User32.EventConstants.EVENT_OBJECT_HIDE:
                    case User32.EventConstants.EVENT_OBJECT_IME_HIDE:
                        SystrayContext.Logger.Information($"window minimized/hide");
                        DesktopWindow removed = DesktopWindowsManager.FindWindow(hwnd);
                        if (removed != null)
                        {
                            DesktopWindowsManager.RemoveWindow(removed);
                        }
                        break;

                    case User32.EventConstants.EVENT_SYSTEM_MOVESIZEEND:
                        SystrayContext.Logger.Information($"window move/size");
                        DesktopWindow moved = DesktopWindowsManager.FindWindow(hwnd);
                        if (moved != null)
                        {
                            DesktopWindow newMoved = new DesktopWindow(hwnd);
                            newMoved.GetInfo();
                            if (!moved.Equals(newMoved))
                            {
                                DesktopWindowsManager.RepositionWindow(moved, newMoved);
                            }
                        }
                        break;

                    case User32.EventConstants.EVENT_OBJECT_DRAGCOMPLETE:
                        SystrayContext.Logger.Information($"window dragged");
                        break;

                    default:
                        break;
                    }
                }
            }

            User32.WinEventProc winEventHookAll = new User32.WinEventProc(WinEventHookAll);
            GCHandle            gchCreate       = GCHandle.Alloc(winEventHookAll);

            User32.HWINEVENTHOOK hookAll = User32.SetWinEventHook(User32.EventConstants.EVENT_MIN, User32.EventConstants.EVENT_MAX, HINSTANCE.NULL, winEventHookAll, 0, 0, User32.WINEVENT.WINEVENT_OUTOFCONTEXT | User32.WINEVENT.WINEVENT_SKIPOWNPROCESS);
        }