WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: cssyphus on July 06, 2025, 08:09:28 AM

Title: Detect if win visible but not focused
Post by: cssyphus on July 06, 2025, 08:09:28 AM
Is there any way to detect if a window is visible but not focused on the screen?

I have a script that watches for a certain condition and, if "SomeApp" is running it does procedure A and if "SomeApp" is not running, it does procedure B.

The problem is that when SomeApp finishes running and is closed, it doesn't really close - so winExist() will still find this program running, even though it is "closed".

For my purposes, all I need to know is if SomeApp is visible on the screen - regardless whether or not it has the focus.

The SomeApp in question is OBS Studio. If it is recording, I do not want Procedure B to run.  When it is recording, the focus may be on OBS Studio, or it may be on the window that is being recorded - but OBS Studio is almost always fully visible on monitor 2 (which is good enough for me... this is not an application where perfect perfection is required - good enough is good enough).

Can anyone think of a way (or did I just forget how...) to detect if OBS Studio is visible on any monitor, regardless if it has the focus or not?
Title: Re: Detect if win visible but not focused
Post by: td on July 06, 2025, 09:19:19 AM
Maybe try AppExist:
https://docs.winbatch.com/mergedProjects/WindowsInterfaceLanguage/html/WILAK_A__005.htm (https://docs.winbatch.com/mergedProjects/WindowsInterfaceLanguage/html/WILAK_A__005.htm)

Title: Re: Detect if win visible but not focused
Post by: cssyphus on July 09, 2025, 12:02:37 PM
AppExist does the trick. Thanks Tony.

Question: if the app is not running, AppExist responds after 5 seconds - but only takes ~ 1 sec if the app is running. Is there a way to change that timeout? Two seconds would work for me, since speed is more important than 100% accuracy in my use case.
Title: Re: Detect if win visible but not focused
Post by: td on July 09, 2025, 01:41:36 PM
Please follow the link, paying attention to the function's 3 parameter.

https://docs.winbatch.com/mergedProjects/WindowsInterfaceLanguage/html/WILAK_A__005.htm (https://docs.winbatch.com/mergedProjects/WindowsInterfaceLanguage/html/WILAK_A__005.htm)
Title: Re: Detect if win visible but not focused
Post by: snowsnowsnow on September 11, 2025, 08:15:27 AM
QuotePlease follow the link, paying attention to the function's 3 parameter.

https://docs.winbatch.com/mergedProjects/WindowsInterfaceLanguage/html/WILAK_A__005.htm (https://docs.winbatch.com/mergedProjects/WindowsInterfaceLanguage/html/WILAK_A__005.htm)

Clicking that line produces:

This site can't be reached
docs.winbatch.com's server IP address could not be found.

DNS_PROBE_FINISHED_NXDOMAIN

(My network connection is otherwise just fine, so don't assume the problem is on my end)
Title: Re: Detect if win visible but not focused
Post by: td on September 11, 2025, 02:58:29 PM
Works fine for me and no one else is complaining.
Title: Re: Detect if win visible but not focused
Post by: snowsnowsnow on September 13, 2025, 06:08:19 AM
QuoteWorks fine for me and no one else is complaining.

Seems to be a problem with my (specifically, my ISP's) DNS.  Everything else works fine, but pinging docs.winbatch.com fails.

It turns out both forum.winbatch.com and docs.winbatch.com fail my DNS and have to be explicitly listed in the hosts file in order to work.

Putting this line in the hosts file fixes things:

68.178.202.14   forum.winbatch.com docs.winbatch.com

Title: Re: Detect if win visible but not focused
Post by: td on September 16, 2025, 09:48:10 AM
We manage our DNS server service, but it does have a bunch of Cloudflare required records. Perhaps your ISP is not Cloudflare friendly. Some of our subdomains are not wrapped with Cloudflare CDN records. Your ISP might not like the some but not all approach.