Skip to content

Commit

Permalink
#21 WindowFinder overhaul: Implemented the supposed Alt-Tab behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
FrigoCoder committed Jan 4, 2018
1 parent 991a0cc commit 72798fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
2 changes: 0 additions & 2 deletions .hgignore → .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
syntax:glob
.*
bin
obj
packages
*.user
28 changes: 25 additions & 3 deletions FrigoTab/WindowFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ private enum WindowType {
private delegate bool EnumWindowsProc (IntPtr handle, IntPtr lParam);

private static WindowType GetWindowType (WindowHandle handle) {
if( handle.GetClassName() == "SWT_Window0" && handle.GetWindowText() == "" ) {
return WindowType.Hidden;
}
if( handle.GetWindowRect().IsEmpty ) {
return WindowType.Hidden;
}
if( Dwm.IsCloaked(handle) ) {
return WindowType.Hidden;
}
if( !IsAltTabWindow(handle) ) {
return WindowType.Hidden;
}

WindowStyles style = handle.GetWindowStyles();
if( style.HasFlag(WindowStyles.Disabled) ) {
Expand All @@ -72,9 +72,31 @@ private static WindowType GetWindowType (WindowHandle handle) {
return WindowType.AppWindow;
}

private static bool IsAltTabWindow (IntPtr hwnd) {
IntPtr hwndWalk = IntPtr.Zero;
IntPtr hwndTry = GetAncestor(hwnd, 3);
while( hwndTry != hwndWalk ) {
hwndWalk = hwndTry;
hwndTry = GetLastActivePopup(hwndWalk);
if( IsWindowVisible(hwndTry) ) {
break;
}
}
return hwndWalk == hwnd;
}

[DllImport("user32.dll")]
private static extern bool EnumWindows (EnumWindowsProc enumFunc, IntPtr lParam);

[DllImport("user32.dll")]
private static extern IntPtr GetAncestor (IntPtr hWnd, int gaFlags);

[DllImport("user32.dll")]
private static extern IntPtr GetLastActivePopup (IntPtr hWnd);

[DllImport("user32.dll")]
private static extern bool IsWindowVisible (IntPtr hWnd);

}

}

0 comments on commit 72798fa

Please sign in to comment.