[RESOLVED] Wait until a process' main Window is displayed
Hello everyone.
I am working on a game launcher, and I need to display a "Splash screen" until the main game has started. For this, I need to know whether or not the Process has a Main window that is fully loaded and displayed.
Now I noticed the main window handle is 0 when there is none, so I tried to use that:
Code:
p.Start()
Do While p.MainWindowHandle = IntPtr.Zero
Threading.Thread.Sleep(100)
Loop
MsgBox("Game window displayed")
But the handle never becomes nonzero. I tried to use the title but to no avail.
I do not want to go into "Thread.wait()" since then the splash would remain even if the game is already launched.
Any help on this?
Re: Wait until a process' main Window is displayed
Does the Application Framework works for you?
Based on what you have described, it is possible with VB2005 via Application Framework. You can even set the delay before the splashscreen is closed after the main form is ready to be loaded.
Re: Wait until a process' main Window is displayed
Quote:
Originally Posted by
bergerkiller
But the handle never becomes nonzero.
Just a guess, but have you tried refresh?
Code:
Do While p.MainWindowHandle = IntPtr.Zero
Threading.Thread.Sleep(100)
p.Refresh()
Loop
Re: Wait until a process' main Window is displayed
You could try calling WaitForInputIdle on the Process.
Re: Wait until a process' main Window is displayed
Thanks edge and jmcil, both working answers.
Never used inputidle because I thought it was related to the "StandardOutput" or "StandardInput" streams, but that is not the case as I know now. :bigyello:
Didn't know you had to refresh a process, thought all the process' properties did was get the information from the system, instead of storing them internally...
I guess I'll use the "WaitForInputIdle()" function, since it is shorter and seems more reliable than checking the handle. :thumb: