private void ActivateWindow(WindowBase window) { if (NativeMethods.IsIconic(window.hWnd)) { // OpenIcon does not restore the window to its previous size (e.g. maximized) // ShowWindow(SW_RESTORE) doesn't redraw some windows correctly (like TortoiseHG commit window) Utilities.RestoreApplication(window.hWnd); System.Threading.Thread.Sleep(NativeMethods.minimizeRestoreDelay); } ForceForegroundWindow(window); CurrentWorkspace.WindowActivated(window.hWnd); }
private void FollowWindow(Workspace fromWorkspace, Workspace toWorkspace, bool follow, WindowBase window) { if (follow) { SwitchToWorkspace(toWorkspace.id, false); ActivateWindow(window); } else if (fromWorkspace.IsCurrentWorkspace) { DoForTopmostWindowForWorkspace(CurrentWorkspace, ActivateWindow); } }
private void ForceForegroundWindow(WindowBase window) { var hWnd = NativeMethods.GetLastActivePopup(window.rootOwner); if (Utilities.WindowIsNotHung(hWnd)) { var foregroundWindow = NativeMethods.GetForegroundWindow(); if (foregroundWindow != hWnd) { if (foregroundWindow == IntPtr.Zero) { TrySetForegroundWindow(hWnd); } else if (Utilities.WindowIsNotHung(foregroundWindow)) { var foregroundWindowThreadId = NativeMethods.GetWindowThreadProcessId(foregroundWindow, IntPtr.Zero); if (NativeMethods.AttachThreadInput(this.windawesomeThreadId, foregroundWindowThreadId, true)) { var targetWindowThreadId = NativeMethods.GetWindowThreadProcessId(hWnd, IntPtr.Zero); var successfullyAttached = foregroundWindowThreadId != targetWindowThreadId && NativeMethods.AttachThreadInput(foregroundWindowThreadId, targetWindowThreadId, true); TrySetForegroundWindow(hWnd); if (successfullyAttached) { NativeMethods.AttachThreadInput(foregroundWindowThreadId, targetWindowThreadId, false); } NativeMethods.AttachThreadInput(this.windawesomeThreadId, foregroundWindowThreadId, false); } } } else { NativeMethods.BringWindowToTop(hWnd); } } }
internal WindowBase(WindowBase window) { this.hWnd = window.hWnd; this.rootOwner = window.rootOwner; }