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).
Detect when a window is no longer busy?
Detect when a window is no longer busy?
Last edited by BarryG on Fri Jul 01, 2022 11:44 am, edited 1 time in total.
Re: Detect when a window is no longer busy?
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.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.
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.
Last edited by Bitblazer on Fri Jul 01, 2022 11:22 am, edited 2 times in total.
Re: Detect when a window is no longer busy?
Code: Select all
if title <> "WordPad" And title <> ""
Re: Detect when a window is no longer busy?
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!
@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?
Maybe WaitForInputIdle could be useful
Re: Detect when a window is no longer busy?
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
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version