Page 1 of 1
Detect when a window is no longer busy?
Posted: Fri Jul 01, 2022 10:22 am
by BarryG
Hi all. I need my app to know as soon as the current foreground window (whatever it is) is ready for user input and not in the loading/opening state. When I open a 500 KB WordPad doc, there's a few seconds delay before it's ready and showing the document title (it just says "WordPad" until then).
See the screenshot below - it's slowly opening the document, and I need to know when this "busy" opening state is finished, so that the caption says whatever the doc title actually is. I don't know the doc title in advance so I can't just test for that. Thanks for any pointers/advice.
[Edit] Forgot to say originally: the window title doesn't always change, so that's why I need to detect the "busy" state instead. I only used WordPad as an example to show what I meant by "busy" (as opposed to "Not Responding" which is not always the same thing).

Re: Detect when a window is no longer busy?
Posted: Fri Jul 01, 2022 11:08 am
by Bitblazer
BarryG wrote: Fri Jul 01, 2022 10:22 am
See the screenshot below - it's slowly opening the document, and I need to know when this "busy" opening state is finished, so that the caption says whatever the doc title actually is. I don't know the doc title in advance so I can't just test for that. Thanks for any pointers/advice.
In that case you could watch for the title change. In general it sounds like you want to know when a windows app is ready to process new windows message queue entries. So the task would be to find a generic windows api message that creates a response and your app would wait for that response. Is there a simple PING->PONG windows api queue message? I remember using such a mechanism in linux
many years ago.
Your third party app injects a PING into the windows message queue of an app and the app simply replies with some kind of PONG. So you know, that the app is ready and processing message queue entries.
This could help finding a windows solution.
Re: Detect when a window is no longer busy?
Posted: Fri Jul 01, 2022 11:15 am
by AZJIO
Code: Select all
if title <> "WordPad" And title <> ""
Re: Detect when a window is no longer busy?
Posted: Fri Jul 01, 2022 11:45 am
by BarryG
First post edited... forgot to say the window title can't be checked for this. My bad.
@BitBlazer: I'll look at the IsHungAppWindow_() function to see if I can work with that. Thanks!
Re: Detect when a window is no longer busy?
Posted: Fri Jul 01, 2022 12:34 pm
by Bitblazer
Maybe
WaitForInputIdle could be useful
Re: Detect when a window is no longer busy?
Posted: Fri Jul 01, 2022 1:08 pm
by Sicro
Code: Select all
;Autor: Sicro
;http://www.purebasic.fr/german/viewtopic.php?p=312984#p312984
EnableExplicit
Define Program
Procedure IsProgramReady(Program.i, MillisecondsToWait.i)
Protected ProgramHandle.i, RetVal.i
ProgramHandle = OpenProcess_(#PROCESS_QUERY_INFORMATION, #False, ProgramID(Program))
If ProgramHandle = 0
ProcedureReturn -1
EndIf
Select WaitForInputIdle_(ProgramHandle, MillisecondsToWait)
Case #WAIT_FAILED: RetVal = -1
Case #WAIT_TIMEOUT: RetVal = #False
Case 0: RetVal = #True
EndSelect
CloseHandle_(ProgramHandle)
ProcedureReturn RetVal
EndProcedure
Program = RunProgram("C:\Program Files\Paint.NET\PaintDotNet.exe", "", "", #PB_Program_Open)
If IsProgram(Program)
; Wait until the program is ready
Repeat
If ProgramRunning(Program)
If IsProgramReady(Program, 100) = #True
Break
EndIf
EndIf
ForEver
Debug "Program is ready"
EndIf