I posted this a few days ago, but here it is again (slightly modified):
Wait until an app is loaded
Wait until an app is closedCode:Private Const SYNCHRONIZE As Long = &H100000 Private Const INFINITE As Long = &HFFFF Private Declare Function WaitForInputIdle _ Lib "user32" _ (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long Private Declare Function CloseHandle _ Lib "kernel32" _ (ByVal hObject As Long) As Long Private Declare Function OpenProcess _ Lib "kernel32" _ (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _ ByVal dwProcessId As Long) As Long Private Sub cmdRunApp_Click() Dim hProcessID As Long Dim hProcess As Long Dim sShellPath As String sShellPath = "C:\WINDOWS\NOTEPAD.EXE" hProcessID = Shell(sShellPath, vbNormalFocus) If hProcessID <> 0 Then hProcess = OpenProcess(SYNCHRONIZE, 0, hProcessID) If hProcess <> 0 Then Call WaitForInputIdle(hProcess, INFINITE) Call CloseHandle(hProcess) End If End If End Sub
Keep in mind the above code is for 32-bit environments, if you're using 16-bit let me know and I'll post the code for it.Code:Private Const SYNCHRONIZE As Long = &H100000 Private Const INFINITE As Long = &HFFFF Private Declare Function WaitForSingleObject _ Lib "kernel32" _ (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Declare Function CloseHandle _ Lib "kernel32" _ (ByVal hObject As Long) As Long Private Declare Function OpenProcess _ Lib "kernel32" _ (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _ ByVal dwProcessId As Long) As Long Private Sub cmdRunApp_Click() Dim hProcessID As Long Dim hProcess As Long Dim sShellPath As String sShellPath = "C:\WINDOWS\NOTEPAD.EXE" hProcessID = Shell(sShellPath, vbNormalFocus) If hProcessID <> 0 Then hProcess = OpenProcess(SYNCHRONIZE, 0, hProcessID) If hProcess <> 0 Then Call Me.Hide App.TaskVisible = False Call WaitForSingleObject(hProcess, INFINITE) Call CloseHandle(hProcess) App.TaskVisible = True Call Me.Show End If End If End Sub
[Edited by SonGouki on 04-06-2000 at 10:59 AM]




Reply With Quote