IfWinExist can't find a window on a different desktop on Windows 10

Report problems with documented functionality
True Falcon
Posts: 2
Joined: 24 Nov 2019, 18:06
Facebook: https://www.facebook.com/TheOnlyTrueFalcon

IfWinExist can't find a window on a different desktop on Windows 10

24 Nov 2019, 19:36

I toggle several programs on or off screen using code like this:

Code: Select all

TogglemIRC:
CapsLock::
	SetTitleMatchMode 2
	IfWinExist %mIRCID%
	{
		IfWinActive %mIRCID%
		{
			WinMinimize %mIRCID%
		}
		Else
		{
			WinActivate %mIRCID%
		}
		Return
	}
	Run C:\Program Files (x86)\mIRC\mirc.exe
	Return
I updated AHK to 1.1.32.00 today and suddenly this does not work if I'm on a different desktop than where mIRC is currently running. Today it starts a new instance of mIRC using my alternate nick (since the primary is in use) on the current desktop. Previously it would switch to the desktop where mIRC was already running and bring it to the front. Since the code is starting a new instance, it the IfWinExist that is failing for me, but I suspect all the "IfWin..." commands will now fail to find an open window on a different desktop.

I downgraded to 1.1.31.00 and now the above code works as intended.
gregster
Posts: 6109
Joined: 30 Sep 2013, 06:48

Re: IfWinExist can't find a window on a different desktop on Windows 10

24 Nov 2019, 19:53

Welcome to the forum!

Probably not a bug, but intended behaviour in version 1.1.32.00.

I assume that the target windows are actually "cloaked". The change log entry for 1.1.32.00 mentions a related change that was made for consistency reasons, I believe:
https://www.autohotkey.com/docs/AHKL_ChangeLog.htm#v1.1.32.00 wrote:Changed commands and functions with a WinTitle parameter to treat cloaked windows as hidden.
Also, the docs explicitly mention that windows on non-active desktops (on Win10) could be affected by this change:
https://www.autohotkey.com/docs/commands/DetectHiddenWindows.htm#Remarks wrote:[v1.1.32+]: Cloaked windows are also considered hidden. This includes suspended Universal Windows Platform apps and windows which are on a non-active virtual desktop (on Windows 10). Such windows are hidden from view, but might still have the WS_VISIBLE window style. Prior to v1.1.32, all windows with the WS_VISIBLE style were considered visible.
(red text color added by me)

You could probably fix this by adding DetectHiddenWindows, On (but look out for side-effects).
True Falcon
Posts: 2
Joined: 24 Nov 2019, 18:06
Facebook: https://www.facebook.com/TheOnlyTrueFalcon

Re: IfWinExist can't find a window on a different desktop on Windows 10

24 Nov 2019, 20:51

Thanks, gregster!

That restored the previous behaviour. I just set the default to On for now. I have no reason at this point to cloak windows, but now, if I ever need to, I'll know how to do it!

😎🚲
gregster
Posts: 6109
Joined: 30 Sep 2013, 06:48

Re: IfWinExist can't find a window on a different desktop on Windows 10

24 Nov 2019, 21:06

Thanks for the feedback!
If I understand the concept of cloaked windows correctly, this problem was rather about detecting cloaked windows than cloaking them yourself.

My understanding is that the "cloaking" is something that might occur on Windows 10, due to broader changes like the introduction of virtual desktops and UWP apps. The question is just how to handle these cloaked windows (which might still have the WS_VISIBLE style) - and that handling was changed by Lexikos in the newest version, so that only actually visible windows on the current desktop are really considered visible by AHK. But I don't know much about cloaked windows myself, so far...
kartunes
Posts: 1
Joined: 03 Jan 2020, 12:20

Re: IfWinExist can't find a window on a different desktop on Windows 10

03 Jan 2020, 14:31

I came here to post this bug. For me, adding DetectHiddenWindows, On does not fix the problem for:

Code: Select all

 ;; Firefox
        #!f::
        if WinExist("ahk_exe firefox.exe")
            WinActivate
         else
            Run "D:\PortableApps(NS)\apps\firefox\current\firefox.exe" 
        Return
When DetectHiddenWindows, On is added at the start of the script, nothing happens after pressing #!f. That is the firefox window is not activated nor is a new instance started.

I have rolled back to the prior version when things worked. Hopefully this gets worked out.
mshafer1
Posts: 54
Joined: 16 Jul 2017, 14:49
GitHub: mshafer1
Contact:

Re: IfWinExist can't find a window on a different desktop on Windows 10

10 Dec 2020, 11:14

kartunes wrote:
03 Jan 2020, 14:31
I came here to post this bug. For me, adding DetectHiddenWindows, On does not fix the problem for:

;; Firefox
#!f::
if WinExist("ahk_exe firefox.exe")
WinActivate
else
Run "D:\PortableApps(NS)\apps\firefox\current\firefox.exe"
Return

When DetectHiddenWindows, On is added at the start of the script, nothing happens after pressing #!f. That is the firefox window is not activated nor is a new instance started.

I have rolled back to the prior version when things worked. Hopefully this gets worked out.
I've found that adding a WinShow (before the WinActivate) makes similar code work for me, but causes undesired behavior with apps like Micorosoft Teams or apps that use a Chrome browser as a hidden window that (as now hidden windows are found and made visble rather than the main app which is visible but cloaked).

Would be nice if we could get a `DetectCloakedWindows`...

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 1 guest