My program opens another program, and I'm needing to know get my program to recognize when that certain program is closed. Any help is appreciated..
Printable View
My program opens another program, and I'm needing to know get my program to recognize when that certain program is closed. Any help is appreciated..
Code:You would have to use a time to keep checking
'finding the hwnd of a window if you know the title
'of the window
'<<<<<<<<<<<<<<<< Bas Module Code >>>>>>>>>>>>>>>>>
'API to get the handle of a window
Declare Function FindWindow Lib "user32.dll" _
Alias "FindWindowA" (ByVal lpClassName As Any, _
ByVal lpWindowName As Any) As Long
'Parameters
'lpClassName
'The name of the window class of the window to find.
'Pass 0 to allow the window to be of any class.
'lpWindowName
'The name of the title bar text of the window to find. '
'Pass 0 to allow the window to have any name.
'<<<<<<<<<<<<<<<<< Form Code >>>>>>>>>>>>>>>>>>>
Option Explicit
Private Sub Command1_Click()
Dim hwnd As Long ' receives handle to the found window
' Attempt to locate a window called Calculator
' Note how the CLng function
' must be used to force 0 as a Long data type.
hwnd = FindWindow(CLng(0), "Calculator") ' look for the window
If hwnd = 0 Then ' could not find the window
MsgBox "Calculator is not currently running."
Else
MsgBox "the hwnd for Calculator is " & hwnd
End If
End Sub
There appears to be an API called: WaitForSingleObject
According the documentation, this API will "simply wait for
a process to return or a timeout to occur..."
Could this be what you want?
Good Luck
DerFarm
Try this:
Code:Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "Kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400
'JobtoDo - Program to run
Sub Shell32Bit(ByVal JobToDo As String)
Dim hProcess As Long
Dim RetVal As Long
'The next line launches JobToDo as icon,
'captures process ID
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(JobToDo, 1))
Do
'Get the status of the process
GetExitCodeProcess hProcess, RetVal
'Sleep command recommended as well as DoEvents
DoEvents: Sleep 100
'Loop while the process is active
Loop While RetVal = STILL_ACTIVE
Msgbox "App has been unloaded!"
End Sub
Usage:
Private Sub Command1_Click()
Call Shell32Bit("C:\App\App.exe")
End Sub
Thanks guys..