Results 1 to 5 of 5

Thread: [RESOLVED] Wait until a process' main Window is displayed

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Resolved [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?

  2. #2
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    485

    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.

  3. #3
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Wait until a process' main Window is displayed

    Quote Originally Posted by bergerkiller View Post
    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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Wait until a process' main Window is displayed

    You could try calling WaitForInputIdle on the Process.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    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.

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width