Window Trouble

Discuss Autohotkey related topics here. Not a place to share code.
Forum rules
Discuss Autohotkey related topics here. Not a place to share code.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Window Trouble

17 Dec 2022, 04:53

On my PC there currently exist a window which causes some issues with ahk. About the window, which is visible,

Code: Select all

WinGetTitle: Setup
ProcessGetName: CodeSetup-stable-6261075646f055b99068d3688932416f2346dd3b.tmp
width: 0
height: 0
ProcessGetPath: \AppData\Local\Temp\is-JG9KB.tmp\CodeSetup-stable-6261075646f055b99068d3688932416f2346dd3b.tmp
WinGetClass: TApplication
Parent:
CodeSetup-stable-6261075646f055b99068d3688932416f2346dd3b.exe
\AppData\Local\Temp\vscode-update-user-x64\CodeSetup-stable-6261075646f055b99068d3688932416f2346dd3b.exe
I search the Internet, and of course this seems to be a microsoft window. :duck: :duck:

The issue I have is that when I try to do (eg) winhide on this window, winhide doesn't return, the script hangs or at the very least stalls. Sometimes I manage to close the script via the tray menu, sometimes I need to end the process via ^!del. I had some success via dllcall(SetWindowPos) and flag SWP_ASYNCWINDOWPOS but couldn't reproduce this now. But this wouldn't help me because I also wanted to use WinSetTransparent which also hangs with this window.

Context, I do stuff with visible windows, I filter by non-blank window title. This is simple and fast and worked well for a long time. Now I will work around by also filter out zero width and height windows. But, I am interested in a general way to identify windows which causes issues like this. This might be something which can be handled by AHK itself. It was not very easy to find out why my script suddenly started to hang.

Cheers.

Edit, tried to fix some of the poor spelling/grammar :?
Last edited by Helgef on 17 Dec 2022, 10:25, edited 1 time in total.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Window Trouble

17 Dec 2022, 08:08

ive found a couple such visible 0 size px dimensional TApplication class windows on my computer, one belonging to WizTree, the other HxD hex editor. none of them hung the ahk script after WinHide/Show(...) and WinSetTransparent(128, ...), so probably ur specific vscode updater window is doing its updating on the ui thread(assuming its even possible for them to have coded it that way, idk how this library works https://docwiki.embarcadero.com/RADStudio/Sydney/en/VCL_Overview)
image.png
image.png (54.95 KiB) Viewed 1891 times
what does IsHungAppWindow() say?
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Window Trouble

17 Dec 2022, 10:22

Thank you very much for your reply and efforts @swagfag :)

IsHungAppWindow() returns 1 :o. I thought AHK called IsHung, but maybe I've dreamt this.

More fun from ms, on IsHung,
Ghost windows always return TRUE.
There is ofc no link or explanation on what this means. Sigh... :facepalm:

I guess filtering on IsHung will be a better general solution than filter on size.

Cheers.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Window Trouble

17 Dec 2022, 10:31

It seems like ahk skips ishung check for hide/show,

Code: Select all

	// Seems safe to assume it's not hung in these cases, since I'm inclined to believe
	// (untested) that hiding and showing a hung window won't lock up our thread, and
	// there's a chance they may be effective even against hung windows, unlike the
	// others above (except ACT_WINMINIMIZE, which has a special FORCE method):
	case FID_WinHide: nCmdShow = SW_HIDE; break;
	case FID_WinShow: nCmdShow = SW_SHOW; break;
It would perhaps be needed for winhide, at least in my case.

Cheers.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Window Trouble

17 Dec 2022, 13:37

Issue demonstration,

Code: Select all

; Script 1
gui(,'helgefffehfelfef').show('w200 h200')
dllcall 'Sleep', 'uint', 15000
exitapp

Code: Select all

; Script 2
+1::{
	hwnd := winexist('helgefffehfelfef')
	tooltip IsHungAppWindow(hwnd)
	winhide hwnd
	tooltip IsHungAppWindow(hwnd)
	exitapp
}
esc::exitapp
IsHungAppWindow(hwnd)
	=> dllcall('IsHungAppWindow', 'ptr', hwnd, 'int')
Run script 1 and 2, wait 5 seconds then press +1

Cheers
lexikos
Posts: 9665
Joined: 30 Sep 2013, 04:07
Contact:

Re: Window Trouble

20 Dec 2022, 00:40

The problem with an internal IsHungAppWindow check is that it might cause the function to have no effect in cases where it might otherwise work, perhaps with a delay. It probably already has that effect for WinMaximize/WinRestore.

The window being "hung" doesn't mean that it won't respond, or that it necessarily won't respond within a given time period, only that the app hasn't checked for messages within a certain time period. If you check within that period, IsHungAppWindow will tell you it isn't hung.

If the user tries to interact with a hung window, the OS replaces it with a placeholder window (ahk_class Ghost) that can be moved, until the app responds again. This is actually a separate window owned by dwm.exe, and the original window is removed from the screen without actually making it "hidden" (IsWindowVisible) or even "cloaked" (DwmGetWindowAttribute/DWMA_CLOAKED). You can get the window corresponding to a ghost window by calling an undocumented function: DllCall("HungWindowFromGhostWindow", "ptr", ghost_hwnd, "ptr"). There's also a GhostWindowFromHungWindow.

dwm.exe doesn't run as the user, so you generally don't have permission to read its process name or move its windows.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Window Trouble

21 Dec 2022, 13:31

thank you for the information :thumbup:

Cheers.
lexikos
Posts: 9665
Joined: 30 Sep 2013, 04:07
Contact:

Re: Window Trouble

22 Dec 2022, 02:04

ShowWindowAsync
An application can use this function to avoid becoming nonresponsive while waiting for a nonresponsive application to finish processing a show-window event.
Source: ShowWindowAsync function (winuser.h) - Win32 apps | Microsoft Learn
It looks like Chris tried ShowWindowAsync, but maybe he didn't consider using it conditionally (i.e. only on hung windows).
// UPDATE: Trying ShowWindowAsync()
// now, which should avoid the problems with hanging. UPDATE #2: Went back to
// not using Async() because sometimes the script lines that come after the one
// that is doing this action here rely on this action having been completed
// (e.g. a window being maximized prior to clicking somewhere inside it).
Then again, in some situations it might be better for the function to wait until the window does respond.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Window Trouble

22 Dec 2022, 08:25

that function might be a good candidate for my use case, thanks again

Cheers 🎄🎅
User avatar
andymbody
Posts: 950
Joined: 02 Jul 2017, 23:47

Re: Window Trouble

22 Dec 2022, 11:53

swagfag wrote:
17 Dec 2022, 08:08
ive found a couple such visible 0 size px dimensional TApplication class windows on my computer, one belonging to WizTree, the other HxD hex editor. none of them hung the ahk script after WinHide/Show(...) and WinSetTransparent(128, ...), so probably ur specific vscode updater window is doing its updating on the ui thread(assuming its even possible for them to have coded it that way, idk how this library works https://docwiki.embarcadero.com/RADStudio/Sydney/en/VCL_Overview)
image.png
what does IsHungAppWindow() say?
Can you tell me what you used to display the 'Window Properties' in the image.png (shown above in post on 12/17). Is this a Win10/11 feature or a custom app (I'm using Win7)?

Thanks!
Andy
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Window Trouble

22 Dec 2022, 13:46

its Spy++
download Visual Studio to get it

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 9 guests