I wrapped these in a loop that closes all blocking windows. This feature will try three different methods to close the current
popup window (from "gentle" to "powerful"). This gives you access to the main window again. I use this function
to automate processes without having to check the status of open windows. For a little more comfort I have made a few
parameters possible. The description of these can be found in the comment block within the function.
Hope, it will work and will be usefull.
Code: Select all
AutoCloseBlockingPopUps(WinID, autoclose:=2) {
/* DESCRIPTION
The function offers 3 possibilities
1. autoclose = 0
only returning an object with two Key: Value pairs, "isblocked": true / false for is blocked and "blockWinT": name of the blocking window,
"errorStr": is allways empty in this case
2. autoclose = 1
Returns the above object and sends an inquiry to the user if the blocking windows may be closed
3. autoclose = 2
all blocking windows are closed without further inquiry, no values are returned
It gets it return value (errorStr) from function AlbisCloseLastActivePopups () , which it passes on to the calling process.
This string returns the success or failure, so that the process can detect errors, to terminate itself, if necessary, or
to take other actions that could lead to success
#############################################################################################################################
die Funktion bietet 3 Möglichkeiten
1. autoclose = 0
ausschließlich Rückgabe eines Objektes mit zwei Key:Value Paaren, a) true/false für ist blockiert und b) Name des blockierenden Fensters
2. autoclose = 1
Rückgabe des oben genannten Objektes und sendet eine Nachfrage an den User ob die blockierenden Fenster geschlossen werden dürfen
3. autoclose = 2
alle blockierenden Fenster werden ohne Rückfrage geschlossen, es werden keine Werte zurück gegeben
von der Funktion AlbisCloseLastActivePopups() bekommt sie den Rückgabewert (errorStr), den sie an die aufrufende Prozeß weiter reicht.
Dieser String gibt den Erfolg oder Mißerfolg zurück , damit der Prozeß Fehler erkennen kann um sich wenn notwendig zu beenden oder
andere Maßnahmen einzuleiten die zum Erfolg führen könnten
*/
errorStr:=""
; WS_DISABLED:= 0x8000000
WinGet, Style, Style, ahk_id %WinID%
blocked:= (Style & 0x8000000) ? true : false
;which window is blocking this window hwnd
phwnd:= DLLCall("GetLastActivePopup", "uint", WinID)
WinGetTitle, title, ahk_id %phwnd%
if (autoclose=1) {
MsgBox, 4, Note, Your main window is blocked`n by one or more popup windows.`n`nShould all windows be closed now?
IfMsgBox, Yes
gosub WinCloseLastActivePopup
} else if (autoclose=2) {
gosub WinCloseLastActivePopups
}
return {"isblocked": blocked, "blockWinT": title, "errorStr": errorStr}
WinCloseLastActivePopups:
Loop {
WinGet, Style, Style, ahk_id %WinID%
blocked:= (Style & 0x8000000) ? true : false
if !blocked
{
errorStr:=""
break
}
phwnd:= DLLCall("GetLastActivePopup", "uint", WinID)
;3 different attempts to close the window from "gentle" to "powerful"
PostMessage, 0x112, 0xF060,,, ahk_id %phwnd% ; 0x112 = WM_SYSCOMMAND, 0xF060 = SC_CLOSE
If ErrorLevel
WinClose, ahk_id %pHwnd%
If ErrorLevel
WinKill, ahk_id %pHwnd%
If ErrorLevel {
WinGetTitle, title, ahk_id %pHwnd%
throw Exception("Can not close entire window : '" . title . "' `n. The function WinCloseLastActivePopups stops here.", -1)
errorStr:="noClose"
break
}
sleep 200
}
return
}