WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
If NOT IsWindow(WinExist("ahk_id" . this_ID))
continue
WinClose, ahk_id %this_ID%
break
}
return
; This checks if a window is, in fact a window.
; As opposed to the desktop or a menu, etc.
IsWindow(hwnd){
WinGet, s, Style, ahk_id %hwnd%
return s & 0xC00000 ? (s & 0x100 ? 0 : 1) : 0
}