Skip to content

Commit

Permalink
More work around missing Alt+Tab windows #36
Browse files Browse the repository at this point in the history
Plus when switching to a window, then activate the last active pop-up.
That is more inline with the regular Alt+Tab.
  • Loading branch information
kvakulo committed Mar 17, 2015
1 parent 4e58c24 commit 2851db6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
24 changes: 19 additions & 5 deletions Core/AppWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
using System.Runtime.Caching;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Media.Imaging;
using ManagedWinapi.Windows;
using Microsoft.Win32;

namespace Switcheroo.Core
{
Expand Down Expand Up @@ -80,6 +78,12 @@ public void SwitchTo()
WinApi.SwitchToThisWindow(HWnd, true);
}

public void SwitchToLastVisibleActivePopup()
{
var lastActiveVisiblePopup = GetLastActiveVisiblePopup();
WinApi.SwitchToThisWindow(lastActiveVisiblePopup, true);
}

public AppWindow Owner
{
get
Expand Down Expand Up @@ -119,7 +123,8 @@ private bool HasWindowTitle()

private bool IsToolWindow()
{
return (ExtendedStyle & WindowExStyleFlags.TOOLWINDOW) == WindowExStyleFlags.TOOLWINDOW;
return (ExtendedStyle & WindowExStyleFlags.TOOLWINDOW) == WindowExStyleFlags.TOOLWINDOW
|| (Style & WindowStyleFlags.TOOLWINDOW) == WindowStyleFlags.TOOLWINDOW;
}

private bool IsAppWindow()
Expand All @@ -133,6 +138,12 @@ private bool IsNoActivate()
}

private bool IsLastActiveVisiblePopup()
{
var lastActiveVisiblePopup = GetLastActiveVisiblePopup();
return new AppWindow(lastActiveVisiblePopup).IsToolWindow() || lastActiveVisiblePopup == HWnd;
}

private IntPtr GetLastActiveVisiblePopup()
{
// Which windows appear in the Alt+Tab list? -Raymond Chen
// http://blogs.msdn.com/b/oldnewthing/archive/2007/10/08/5351207.aspx
Expand All @@ -146,9 +157,12 @@ private bool IsLastActiveVisiblePopup()
{
hwndTry = hwndWalk;
hwndWalk = WinApi.GetLastActivePopup(hwndTry);
if (WinApi.IsWindowVisible(hwndWalk)) break;
if (WinApi.IsWindowVisible(hwndWalk))
{
return hwndWalk;
}
}
return hwndWalk == HWnd;
return hwndWalk;
}

private bool IsOwnerOrOwnerNotVisible()
Expand Down
11 changes: 8 additions & 3 deletions ManagedWinapi/SystemWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
using System.Windows.Forms;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using ManagedWinapi.Windows.Contents;

namespace ManagedWinapi.Windows
Expand All @@ -34,7 +33,7 @@ namespace ManagedWinapi.Windows
/// </summary>
/// <seealso cref="SystemWindow.Style"/>
[Flags]
public enum WindowStyleFlags
public enum WindowStyleFlags : long
{
/// <summary>
/// WS_OVERLAPPED
Expand Down Expand Up @@ -170,6 +169,12 @@ public enum WindowStyleFlags
/// WS_CHILDWINDOW
/// </summary>
CHILDWINDOW = CHILD,

/// <summary>
/// Usually WindowExStyleFlags.TOOLWINDOW should be used, but it seems like the style
/// is sometimes placed in the Style instead of ExtentedStyle
/// </summary>
TOOLWINDOW = 0x00000080
}

/// <summary>
Expand Down Expand Up @@ -646,7 +651,7 @@ public WindowStyleFlags Style
{
get
{
return (WindowStyleFlags)GetWindowLongPtr(_hwnd, (int)(GWL.GWL_STYLE));
return (WindowStyleFlags)(long)GetWindowLongPtr(_hwnd, (int)(GWL.GWL_STYLE));
}
set
{
Expand Down
2 changes: 1 addition & 1 deletion Switcheroo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private void Switch()
if (lb.Items.Count > 0)
{
var win = (AppWindowViewModel) (lb.SelectedItem ?? lb.Items[0]);
win.AppWindow.SwitchTo();
win.AppWindow.SwitchToLastVisibleActivePopup();
}
HideWindow();
}
Expand Down

0 comments on commit 2851db6

Please sign in to comment.