WaitProgramInitialisation

Share your advanced PureBasic knowledge/code with the community.
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

WaitProgramInitialisation

Post by Droopy »

Code updated for 5.20+

This function is usefull for sending key, and be sure the program is initialised.

Code: Select all

;/ Author : Bingo
; The WaitProgramInitialisation function waits Until The specified process is waiting For user input 
; with no input pending, Or Until The time-out interval has elapsed.
; If this process is a console application or does not have a message queue, 
; WaitProgramInitialisation returns immediately. 

Procedure WaitProgramInitialisation(Handle)  
  While  WaitForInputIdle_(Handle, 1) > 0 
    Debug "Initialisation ..."
    Delay(1) 
  Wend 
EndProcedure

;/ Test
ret = RunProgram("Calc.exe") 
If ret
  WaitProgramInitialisation(ret)
EndIf
Debug "Launched & Ready."
Thanks to Bingo
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: WaitProgramInitialisation

Post by PB »

Nice tip, Bingo -- and thanks for letting us know, Droopy! :)

Normally I'd launch and watch for the app's window to appear (in a loop),
but this is so much cleaner and more efficient -- and doesn't depend on
the title text either (which is good for different languages).
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: WaitProgramInitialisation

Post by PB »

@Fred: Maybe the RunProgram command could have the flags changed, and
the tip above added? I was thinking something like this:

1: Launch the program in invisible mode
2: Wait until the launched program is ready
3: Wait until the launched program quits

What do you think?

(And to those who think the new numbers will confuse things, it's easy enough
to just renumber them manually... the numbers above make more sense due
to being numbered in the sequence that the app is launched).
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply