Exemple #1
0
        /// <summary>
        /// Move window from one screen to another
        /// </summary>
        public void MoveWindowBetweenScreens(Win32Window window, Screen source, Screen target)
        {
            if (window.IsMinimized && !target.Primary)
            {
                MoveToSecondary(window);
                SecondDisplayProcess proc = CachedProcesses.Get(window.Handle.ToInt32());
                if (proc != null)
                {
                    proc.MoveToScreenOnFirstShow = target;
                }
            }
            else
            {
                Rectangle r = window.Bounds;

                int dx = r.Left - source.WorkingArea.Left;
                int dy = r.Top - source.WorkingArea.Top;

                Native.SetWindowPos(window.Handle, IntPtr.Zero, target.WorkingArea.Left + dx, target.WorkingArea.Top + dy,
                                    r.Width, r.Height, 0);
            }
        }
        public void WinEventProc(IntPtr hWinEventHook, uint eventType,
                                 IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
        {
            if (!_monitoring)
            {
                return;
            }

            if (eventType == Native.EVENT_SYSTEM_SWITCHSTART)
            {
                MoveTaskSwitcherToSecond(hwnd);
            }

            if (idObject != Native.OBJID_WINDOW)
            {
                return;
            }

            if (eventType == Native.EVENT_SYSTEM_FOREGROUND)
            {
                if (TaskbarPropertiesManager.Instance.Properties.ShowStartMenu && Native.GetClassName(hwnd).Equals("DV2ControlHost"))
                {
                    OnStartMenu(hwnd, Native.IsStartMenuVisible());
                }
                else
                {
                    var proc = CachedProcesses.Get(hwnd.ToInt32());
                    if (proc != null && proc.MoveToScreenOnFirstShow != null)
                    {
                        MoveWindowToSecond(hwnd);
                        proc.MoveToScreenOnFirstShow = null;
                        return;
                    }

                    OnWindowMoved(hwnd);
                    OnFocus(hwnd);
                }
            }
            else if (eventType == Native.EVENT_SYSTEM_MOVESIZEEND)
            {
                OnWindowMoved(hwnd);
            }
            else if (eventType == Native.EVENT_OBJECT_DESTROY)
            {
                OnLocationChanged(hwnd);
                OnWindowDestroyed(hwnd);
                CachedProcesses.Remove(hwnd.ToInt32());
            }
            else if (eventType == Native.EVENT_SYSTEM_LOCATIONCHANGE || eventType == Native.EVENT_OBJECT_SHOW)
            {
                string className = Native.GetClassName(hwnd);

                if (TaskbarPropertiesManager.Instance.Properties.ShowStartMenu && className.Equals("DV2ControlHost"))
                {
                    OnStartMenu(hwnd, Native.IsStartMenuVisible());
                }

                if (!Screen.FromPoint(Cursor.Position).Primary&& className.Contains("ClockFlyoutWindow"))
                {
                    OnClockWindow(hwnd);
                }

                OnLocationChanged(hwnd);

                OnWindowMoved(hwnd);

                MoveWindowIfLaunchedFromSecond(hwnd);
            }
            else if (eventType == Native.EVENT_OBJECT_HIDE)
            {
                OnWindowHidden(hwnd);
            }
        }