Detect when a window is no longer busy?

Windows specific forum
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Detect when a window is no longer busy?

Post 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).

Image
Last edited by BarryG on Fri Jul 01, 2022 11:44 am, edited 1 time in total.
Bitblazer
Enthusiast
Enthusiast
Posts: 732
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: Detect when a window is no longer busy?

Post 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.
Last edited by Bitblazer on Fri Jul 01, 2022 11:22 am, edited 2 times in total.
webpage - discord chat links -> purebasic GPT4All
AZJIO
Addict
Addict
Posts: 1312
Joined: Sun May 14, 2017 1:48 am

Re: Detect when a window is no longer busy?

Post by AZJIO »

Code: Select all

if title <> "WordPad" And title <> ""
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Detect when a window is no longer busy?

Post 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!
Bitblazer
Enthusiast
Enthusiast
Posts: 732
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: Detect when a window is no longer busy?

Post by Bitblazer »

Maybe WaitForInputIdle could be useful
webpage - discord chat links -> purebasic GPT4All
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Detect when a window is no longer busy?

Post by Sicro »

Bitblazer wrote: Fri Jul 01, 2022 12:34 pm Maybe WaitForInputIdle could be useful

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
Image
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
Post Reply