WinWaitClose() hangs when Msgbox() run in TimeOut Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
daywalker
Posts: 32
Joined: 18 Jun 2019, 01:37

WinWaitClose() hangs when Msgbox() run in TimeOut

08 May 2023, 09:05

Hello,

running the script, as long you press always manually the Msgbox-Button all runs fine. But when let the Msgbox run in the 1 secs Timeout whole script is blocked, and nothing works.
Did i make a mistake?

Code: Select all

Gui, SelectRef:Add, Button,  gSelectRefButtonOK w250 h60 , Can you press me (click to repeat)?
Gui, SelectRef: -SysMenu HwndHwndSelectRef
Process, Exist
PID=%Errorlevel%
GroupAdd, SelectRef, ahk_pid %PID% ahk_id %HwndSelectRef%
Gui, SelectRef:Show, Hide AutoSize Center, Example
Gui, SelectRef:Default

loop {
	
	Msgbox,  0x2040, , DONT PRESS OK NOW!, 1  ; Dont CLICK OK, let in run in TIMEOUT!
	
	Gui, SelectRef:Show,,Example
	WinWaitClose, ahk_group SelectRef  ; ONLY hangs here, when Msgbox above runs in TimeOut
}
Exitapp ; never reached

SelectRefButtonOK:
	Gui, SelectRef:Submit
Return
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: WinWaitClose() hangs when Msgbox() run in TimeOut

08 May 2023, 10:01

Simplification can be a useful strategy in debugging. When you then have a script that works, you can add one thing at a time to see when it breaks. It makes the troubleshooting fast and relatively simple.

Code: Select all

#Requires AutoHotkey v1.1.33
Gui +HwndHwndSelectRef
Gui Add, Button, gSelectRefButtonOK w250 h60, Can you press me (click to repeat)?
Loop {
 Msgbox 0, Test, DONT PRESS OK NOW!, 1
 Gui Show,, Example
 SoundBeep 1500
 WinWaitClose % "ahk_id" HwndSelectRef
 SoundBeep 1000
}

SelectRefButtonOK:
SoundBeep 2000
Gui Submit
Return
daywalker
Posts: 32
Joined: 18 Jun 2019, 01:37

Re: WinWaitClose() hangs when Msgbox() run in TimeOut

09 May 2023, 00:51

I realized now, that the MsgBox Group #4 Modality is the root cause, but I did not understand why. Why does it work with Options < 0x2000 and does not when >= 0x2000 ?

Code: Select all

#Requires AutoHotkey v1.1.33
Gui +HwndHwndSelectRef
Gui Add, Button, gSelectRefButtonOK w250 h60, Can you press me (click to repeat)?
Loop {
 Msgbox 0, Test, DONT PRESS OK NOW!, 1	;works
 ;Msgbox 0x1000, Test, DONT PRESS OK NOW!, 1	;works
 ;Msgbox 0x2000 , Test, DONT PRESS OK NOW!, 1 ; DONT work, hang when Msgbox above runs in TimeOut
 ;Msgbox 0x40000, Test, DONT PRESS OK NOW!, 1	; DONT work, hang when Msgbox above runs in TimeOut
 Gui Show,, Example
 SoundBeep 1500
 WinWaitClose % "ahk_id" HwndSelectRef
 SoundBeep 1000
}

SelectRefButtonOK:
SoundBeep 2000
Gui Submit
Return
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: WinWaitClose() hangs when Msgbox() run in TimeOut  Topic is solved

09 May 2023, 05:52

From lexikos:
The system disables the script's windows, and does not re-enable them if we kill the dialog using EndDialog. If we close the dialog window, AutoHotkey doesn't get the result code which tells it the MsgBox timed out. We can't close the dialog in the first place if it doesn't have a close button (e.g. because it's a Yes/No dialog). If there's only an OK button the system doesn't return the EndDialog code anyway, so AutoHotkey also sets a flag to let it know the timeout occurred. However, this only works if the thread which showed the MsgBox is the top-most thread when the timeout elapses. The simplest workaround if you have only one Gui is to just use Gui +OwnDialogs instead of the task-modal flag.
viewtopic.php?p=54656#p54656

viewtopic.php?f=14&t=112107

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Spawnova and 287 guests