У меня оба кода обновляют порядок использования окон, только после перезагрузки скрипта. #62.
Взял твою IsAltTabWindow, не знаю вроде и без неё работает также, на всякий случай пока.
Судя по первым тестам работает как надо. Проходит список окон программы в соответствии использования.
1::ParseAltTab("Prev")
2::ParseAltTab("Next")
3::PrevAltTab()
ParseAltTab(dir) {
AltTabList := []
source := WinExist("A")
WinGetClass, sClass, ahk_id %source%
WinGet, sProcess, ProcessName, ahk_id %source%
Winget, List, List, ahk_class %sClass% ahk_exe %sProcess%
Loop % List
{
hwnd := List%A_Index%
If (IsAltTabWindow(hWnd) && source != hwnd) {
AltTabList.Push(hwnd)
}
}
If (dir = "Prev") {
hwnd := AltTabList[1]
} Else {
hwnd := AltTabList[AltTabList.Count()]
}
WinShow ahk_id %hwnd%
WinActivate ahk_id %hwnd%
If (AltTabList.Count() > 1)
; https://learn.microsoft.com/ru-ru/windows/win32/api/winuser/nf-winuser-setwindowpos
DllCall("SetWindowPos", "Ptr", source, "Ptr", AltTabList[AltTabList.Count()]
, "Int", 0, "Int", 0, "Int", 0, "Int", 0, "UInt", 0x0002|0x0001|0x0010)
}
PrevAltTab() {
source := WinExist("A")
WinGetClass, sClass, ahk_id %source%
WinGet, sProcess, ProcessName, ahk_id %source%
Winget, List, List, ahk_class %sClass% ahk_exe %sProcess%
Loop % List
{
hwnd := % List%A_Index%
If (IsAltTabWindow(hWnd) && source != hwnd) {
WinShow ahk_id %hwnd%
WinActivate ahk_id %hwnd%
Break
}
}
}
Return
4::
; MouseGetPos
source := WinExist("A")
DetectHiddenWindows On
arr := EnumerateAltTabWindows()
for k, v in arr
{
WinGetClass, winClass, ahk_id %v%
WinGetTitle, title, ahk_id %v%
altTabWindows .= A_Index "`nTitle: " title "`nClass: " winClass "`nhWnd: " v "`nLastActivePopup: " format("0x{:x}", GetLastActivePopup(v)) "`n`n"
}
MsgBox, % altTabWindows
Return
EnumerateAltTabWindows()
{
AltTabList := []
WinGet, list, List
Loop % list
{
if IsAltTabWindow(list%A_Index%)
AltTabList.Push(list%A_Index%)
}
Return AltTabList
}
IsAltTabWindow(hWnd)
{
static WS_EX_APPWINDOW := 0x40000, WS_EX_TOOLWINDOW := 0x80, DWMWA_CLOAKED := 14, DWM_CLOAKED_SHELL := 2, WS_EX_NOACTIVATE := 0x8000000, GA_PARENT := 1, GW_OWNER := 4, MONITOR_DEFAULTTONULL := 0, VirtualDesktopExist, PropEnumProcEx := RegisterCallback("PropEnumProcEx", "Fast", 4)
if (VirtualDesktopExist = "")
{
OSbuildNumber := StrSplit(A_OSVersion, ".")[3]
if (OSbuildNumber < 14393)
VirtualDesktopExist := 0
else
VirtualDesktopExist := 1
}
if !DllCall("IsWindowVisible", "uptr", hWnd)
return
DllCall("DwmApi\DwmGetWindowAttribute", "uptr", hWnd, "uint", DWMWA_CLOAKED, "uint*", cloaked, "uint", 4)
if (cloaked = DWM_CLOAKED_SHELL)
return
if (realHwnd(DllCall("GetAncestor", "uptr", hwnd, "uint", GA_PARENT, "ptr")) != realHwnd(DllCall("GetDesktopWindow", "ptr")))
return
WinGetClass, winClass, ahk_id %hWnd%
if (winClass = "Windows.UI.Core.CoreWindow")
return
if (winClass = "ApplicationFrameWindow")
{
varsetcapacity(ApplicationViewCloakType, 4, 0)
DllCall("EnumPropsEx", "uptr", hWnd, "ptr", PropEnumProcEx, "ptr", &ApplicationViewCloakType)
if (numget(ApplicationViewCloakType, 0, "int") = 1) ; https://github.com/kvakulo/Switcheroo/commit/fa526606d52d5ba066ba0b2b5aa83ed04741390f
return
}
; if !DllCall("MonitorFromWindow", "uptr", hwnd, "uint", MONITOR_DEFAULTTONULL, "ptr") ; test if window is shown on any monitor. alt-tab shows any window even if window is out of monitor.
; return
WinGet, exStyles, ExStyle, ahk_id %hWnd%
if (exStyles & WS_EX_APPWINDOW)
{
if DllCall("GetProp", "uptr", hWnd, "str", "ITaskList_Deleted", "ptr")
return
if (VirtualDesktopExist = 0) or IsWindowOnCurrentVirtualDesktop(hwnd)
return true
else
return
}
if (exStyles & WS_EX_TOOLWINDOW) or (exStyles & WS_EX_NOACTIVATE)
return
loop
{
hwndPrev := hwnd
hwnd := DllCall("GetWindow", "uptr", hwnd, "uint", GW_OWNER, "ptr")
if !hwnd
{
if DllCall("GetProp", "uptr", hwndPrev, "str", "ITaskList_Deleted", "ptr")
return
if (VirtualDesktopExist = 0) or IsWindowOnCurrentVirtualDesktop(hwndPrev)
return true
else
return
}
if DllCall("IsWindowVisible", "uptr", hwnd)
return
WinGet, exStyles, ExStyle, ahk_id %hwnd%
if ((exStyles & WS_EX_TOOLWINDOW) or (exStyles & WS_EX_NOACTIVATE)) and !(exStyles & WS_EX_APPWINDOW)
return
}
}
GetLastActivePopup(hwnd)
{
static GA_ROOTOWNER := 3
hwnd := DllCall("GetAncestor", "uptr", hwnd, "uint", GA_ROOTOWNER, "ptr")
hwnd := DllCall("GetLastActivePopup", "uptr", hwnd, "ptr")
return hwnd
}
IsWindowOnCurrentVirtualDesktop(hwnd)
{
static IVirtualDesktopManager
if !IVirtualDesktopManager
IVirtualDesktopManager := ComObjCreate(CLSID_VirtualDesktopManager := "{AA509086-5CA9-4C25-8F95-589D3C07B48A}", IID_IVirtualDesktopManager := "{A5CD92FF-29BE-454C-8D04-D82879FB3F1B}")
DllCall(NumGet(NumGet(IVirtualDesktopManager+0), 3*A_PtrSize), "ptr", IVirtualDesktopManager, "uptr", hwnd, "int*", onCurrentDesktop) ; IsWindowOnCurrentVirtualDesktop
return onCurrentDesktop
}
PropEnumProcEx(hWnd, lpszString, hData, dwData)
{
if (strget(lpszString, "UTF-16") = "ApplicationViewCloakType")
{
numput(hData, dwData+0, 0, "int")
return false
}
return true
}
realHwnd(hwnd)
{
varsetcapacity(var, 8, 0)
numput(hwnd, var, 0, "uint64")
return numget(var, 0, "uint")
}