I'm doing some application that when executed, starts a few others and hide their windows. For hiding the windows i'm using the ShowHindow() API but I'm having a little problem, the code is this:
It works, but there's one problem... I tried this on notepad and it worked, tried on another applications and it didn't work because the MainWindowHandle was 0... if I add a System.Threading.Thread.Sleep(500) before the ShowWindow() call, it would work for most of the applications.
What can I do to make sure, every started application is hidden without having to use Sleep()? Some apps may need 0.5s others, may need a bit more or less and I would like to have something that checks the MainWindowHandle and hide it, when it's created.
Can anyone help me out?
Visual Basic:
Friend Const SW_HIDE As Integer = 0
Friend Const SW_RESTORE As Integer = 9
<System.Runtime.InteropServices.DllImport("user32.dll")> _
Friend Function ShowWindow(ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
End Function
Dim fileProcess As Process
fileProcess = Process.Start(appPath)
fileProcess.WaitForInputIdle()
ShowWindow(CType(fileProcess.MainWindowHandle, Integer), SW_HIDE)
It works, but there's one problem... I tried this on notepad and it worked, tried on another applications and it didn't work because the MainWindowHandle was 0... if I add a System.Threading.Thread.Sleep(500) before the ShowWindow() call, it would work for most of the applications.
What can I do to make sure, every started application is hidden without having to use Sleep()? Some apps may need 0.5s others, may need a bit more or less and I would like to have something that checks the MainWindowHandle and hide it, when it's created.
Can anyone help me out?