Code:
;----------------------------------------------------------------------------------------------
; Function: ShowModal
; Show GUI modaly. The script continues after the GUI is closed.
;
; Parameters:
; hGui - GUI number of the window to be shown
; hParent - Parents GUI number. Parent will be disabled while hGui is active
;
; Remarks:
; When the function returns, default gui will be set to hGui.
;
ShowModal( hGui, hParent ) {
gui %hParent%:+Disabled
gui %hParent%:+LastFound
hp := WinExist()
Gui, %hGui%:Default
Gui, +LastFound
hc := WinExist()
ShowModal_OnA(hc,hp,"set",0)
Gui %hGui%:Show
old := OnMessage(6, "ShowModal_OnA")
WinWaitClose, ahk_id %hc%
gui %hParent%:-Disabled
OnMessage(6, old)
}
ShowModal_OnA(wparam, lparam, msg, hwnd){
static hc, hp
if msg = set
return hc := wparam, hp := lparam
if (wparam & 0xFF) and (hwnd = hp)
WinActivate ahk_id %hc%
}
Example:
Code:
Gui, 2:add, button, gOnbutton, open modal window
Gui, 2:Show, autsize
return
Create(){
Gui, 3:add, text, , some text
Gui, 3:Show, x400 y400 Hide autsize
}
GuiClose:
ExitApp
return
OnButton:
hwnd := Create()
ShowModal(3, 2)
msgbox after
return