void tracking() { WinSys.GetWindowRect(windowHandle, ref followedWindowSize); WinSys.GetWindowPlacement( windowHandle, ref windowInformation); // if the window has been maximized if ( (windowInformation.flags & WinSys.SW_SHOWMAXIMIZED) != 0 || (windowInformation.flags & WinSys.SW_MAXIMIZE) != 0) { currentState = TrackingState.WaitingMaximization; windowFollowTimer.Interval = fastTimerInterval; } else { if ( WinSys.RECT.Diff( oldPos, followedWindowSize ) > 0 ) { #if LOGGING logEvent( "% Moved < " + followedWindowSize.Left.ToString() + ", " + followedWindowSize.Top.ToString() + ", " + (followedWindowSize.Right - followedWindowSize.Left).ToString() + ", " + (followedWindowSize.Bottom - followedWindowSize.Top).ToString() + " >" ); #endif Left = Math.Max( followedWindowSize.Left - Width, 0 ); Top = followedWindowSize.Top; Height = followedWindowSize.Bottom - followedWindowSize.Top; oldPos = followedWindowSize; // here we handle the speedup to follow the window // to obtain a smoother move lastWindowMove = 0; if (windowFollowTimer.Interval != fastTimerInterval) windowFollowTimer.Interval = fastTimerInterval; } else if (windowFollowTimer.Interval.Milliseconds == fastTimerInterval.Milliseconds) { // when the window don't move anymore, we hope to bring // back the old slow timer. lastWindowMove += fastTimerInterval.Milliseconds; if (lastWindowMove > maxWaitDelay) windowFollowTimer.Interval = windowFollowDelay; } WinSys.GetWindowRect(thisHandle, ref thisWindowSize ); WinSys.SetWindowPos( thisHandle , windowHandle , thisWindowSize.Left , thisWindowSize.Top , thisWindowSize.Right - thisWindowSize.Left , thisWindowSize.Bottom - thisWindowSize.Top , 0); } }
/// <summary> /// In this method, we wait till the window has finished it's animation /// of maximization to tackle ourselves nearby, without changing the /// maximization state. /// </summary> void waitingMaximization() { WinSys.GetWindowRect(windowHandle, ref followedWindowSize); // animation is finished. if ( WinSys.RECT.Diff( oldPos, followedWindowSize ) == 0 ) { // ok, the user just to maximize it, we're gonna give it to him WinSys.GetWindowRect( thisHandle, ref thisWindowSize); int thisWidth = thisWindowSize.Right - thisWindowSize.Left; Left = Math.Max( followedWindowSize.Left - thisWidth, 0 ); Top = followedWindowSize.Top; Height = followedWindowSize.Bottom - followedWindowSize.Top; WinSys.SetWindowPos( windowHandle , IntPtr.Zero , followedWindowSize.Left + thisWidth , followedWindowSize.Top , followedWindowSize.Right - followedWindowSize.Left - thisWidth , followedWindowSize.Bottom - followedWindowSize.Top , 0 ); WinSys.SetWindowPos( thisHandle , windowHandle , followedWindowSize.Left , followedWindowSize.Top , thisWidth , followedWindowSize.Bottom - followedWindowSize.Top , 0 ); currentState = TrackingState.Maximized; windowFollowTimer.Interval = windowFollowDelay; } oldPos = followedWindowSize; }
public ViewWindow() { InitializeComponent(); watcher = null; windowFollowTimer = new DispatcherTimer(); windowFollowTimer.Tick += new EventHandler(FollowPIDWindow); windowFollowTimer.Interval = windowFollowDelay; // just to be sure to start with a long timer. lastWindowMove = maxWaitDelay + 1; followedWindowSize = new WinSys.RECT(); oldPos = new WinSys.RECT(); windowInformation = new WinSys.WINDOWPLACEMENT(); windowInformation.length = 3 * sizeof(int) + 2 * 2 * sizeof(int) // POINT + 1 * 4 * sizeof(int); // RECT #if LOGGING logEvent( "= Init : " + Environment.OSVersion.Version.Major.ToString() ); #endif }