Page 1 of 1

Multiple winclose windows

Posted: 02 Aug 2019, 10:16
by hannahelappin
Hi,

I want multiple sofware pop up boxes to automatically close. Works for the first "Warning" window but not the next.
Loop
{
WinWait, Warning
WinClose, Warning
}


Loop
{
WinWait, information
WinClose, information
} Any help much appreciated.

Re: Multiple winclose windows

Posted: 02 Aug 2019, 10:40
by GEV
Best solution (in my opinion):

Code: Select all

GroupAdd, Unwanted_Windows, Warning
GroupAdd, Unwanted_Windows, information

Loop
{
	WinWait, ahk_group Unwanted_Windows
	WinClose
}

Re: Multiple winclose windows

Posted: 03 Aug 2019, 07:04
by Alibaba
Hello hannahelappin,

just to clarify a bit why your current solution is not working: Your script will never leave the first loop, so the second loop is “dead code”.

A (unconditional) loop like you are using will only be exited by instructing the script to do so. Take a look at the break statement.

I recommend GEVs solution.

Re: Multiple winclose windows

Posted: 03 Aug 2019, 09:12
by Sid4G
Alibaba wrote:
03 Aug 2019, 07:04
Hello hannahelappin,

just to clarify a bit why your current solution is not working: Your script will never leave the first loop, so the second loop is “dead code”.

A (unconditional) loop like you are using will only be exited by instructing the script to do so. Take a look at the break statement.

I recommend GEVs solution.
So using groups it loops automatically without having to write the sequence manually?

Re: Multiple winclose windows

Posted: 03 Aug 2019, 11:03
by Alibaba
Sid4G wrote:
03 Aug 2019, 09:12
So using groups it loops automatically without having to write the sequence manually?
Well you could think of it like that if it makes it easy to understand, but how WinWait does this internally depends on its implementation in the AHK source code. Using a loop to repeatedly check a condition is called busy waiting (link fyi) but I guess that WinWait is based on system events instead. You should avoid busy waiting whenever possible. (While again this doesn't always apply for low-level programming and use cases :P )

Re: Multiple winclose windows

Posted: 03 Aug 2019, 15:57
by Sid4G
Alibaba wrote:
03 Aug 2019, 11:03
Sid4G wrote:
03 Aug 2019, 09:12
So using groups it loops automatically without having to write the sequence manually?
Well you could think of it like that if it makes it easy to understand, but how WinWait does this internally depends on its implementation in the AHK source code. Using a loop to repeatedly check a condition is called busy waiting (link fyi) but I guess that WinWait is based on system events instead. You should avoid busy waiting whenever possible. (While again this doesn't always apply for low-level programming and use cases :P )
Busy waiting or... a game 8-)

Re: Multiple winclose windows

Posted: 04 Aug 2019, 14:42
by hannahelappin
GEV, Alibaba that’s great guys thanks a lot. I’m new to this and I guessed that my second loop was dead code. Just was a bit lazy really copying something I’d read on another site.

Many thanks for your help that script works great 👍