Results will be refined and contain only Alt+Tab qualified windows.
If the extra 5th parameter is True, then minimized windows will be excluded from results.
Usage example: Use Alt+MouseWheel instead of Alt-tab to switch between windows.
(Note: The following is based on user-observation. This is a work-in-progress)
Shows an UI with a list of top-level windows that meets following criteria:
The window
- 1) Should be visible (WS_VISIBLE) and not cloaked (DWMWA_CLOAKED).
- 2) Should allow activation (Not WS_EX_NOACTIVATE).
- 3) Should not be a floating toolbar (WS_EX_TOOLWINDOW) unless it is also an App window (WS_EX_APPWINDOW).
- 4) Should be an unowned window or an owned window with WS_EX_APPWINDOW style.
or, if an owned window without WS_EX_APPWINDOW style, then
- 1) Should be the first visible window of the owner-chain, and
- 2) None of the preceding invisible owner windows should be a *floating toolbar. (WS_EX_TOOLWINDOW)
*floating toolbar which is also an app window (WS_EX_APPWINDOW) is exempted.
- 1) Finds the RootOwner handle of selected window by calling GetAncestor()
- 2) Passes the RootOwner handle to *GetLastActivePopup() and
- 3) Activates the window returned by it.
- 1) The last active window in an owner chain. (or the first window if the chain never had an active one)
- 2) The same window for an unowned window. (irrespective of whether it was active or not)
The function:. Tested on Window 7, 10, and 11
Code: Select all
WinGetListAlt(params*) ; v0.21 by SKAN for ah2 on D51K/D51O @ autohotkey.com/r?t=99157
{
Static S_OK := 0
Local hModule := DllCall("Kernel32\LoadLibrary", "str","dwmapi", "ptr")
, List := []
, ExMin := 0
, Style := 0
, ExStyle := 0
, hwnd := 0
While params.Length > 4
ExMin := params.pop()
For , hwnd in WinGetList(params*)
If IsVisible(hwnd)
and StyledRight(hwnd)
and NotMinimized(hwnd)
and IsAltTabWindow(hwnd)
List.Push(hwnd)
DllCall("Kernel32\FreeLibrary", "ptr",hModule)
Return List
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IsVisible(hwnd, Cloaked:=0)
{
If S_OK = 0
S_OK := DllCall( "dwmapi\DwmGetWindowAttribute", "ptr",hwnd
, "int", 14 ; DWMWA_CLOAKED
, "uintp", &Cloaked
, "int", 4 ; sizeof uint
)
Style := WinGetStyle(hwnd)
Return (Style & 0x10000000) and not Cloaked ; WS_VISIBLE
}
StyledRight(hwnd)
{
ExStyle := WinGetExStyle(hwnd)
Return (ExStyle & 0x8000000) ? False ; WS_EX_NOACTIVATE
: (ExStyle & 0x40000) ? True ; WS_EX_APPWINDOW
: (ExStyle & 0x80) ? False ; WS_EX_TOOLWINDOW
: True
}
NotMinimized(hwnd)
{
Return ExMin ? WinGetMinMax(hwnd) != -1 : True
}
IsAltTabWindow(Hwnd)
{
ExStyle := WinGetExStyle(hwnd)
If ( ExStyle & 0x40000 ) ; WS_EX_APPWINDOW
Return True
While hwnd := DllCall("GetParent", "ptr",hwnd, "ptr")
{
If IsVisible(Hwnd)
Return False
ExStyle := WinGetExStyle(hwnd)
If ( ExStyle & 0x80 ) ; WS_EX_TOOLWINDOW
and not ( ExStyle & 0x40000 ) ; WS_EX_APPWINDOW
Return False
}
Return !Hwnd
}
} ; ________________________________________________________________________________________________________