Отслеживание закрытия внешней программы запущенной из моего проекта - VB
Формулировка задачи:
Где то затрагивалась иема по поводу отслеживания закрытия внешней программы запущенной из моего проекта - но не могу найти.
Решение задачи: «Отслеживание закрытия внешней программы запущенной из моего проекта»
textual
Листинг программы
Const STILL_ACTIVE = 259
Const NORMAL_PRIORITY_CLASS = &H20
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Declare Function CreateProcess Lib 'kernel32' Alias 'CreateProcessA' (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function GetExitCodeProcess Lib 'kernel32' (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Sub Form_Load()
Dim info As PROCESS_INFORMATION
Dim code As Long, si As STARTUPINFO, sa As SECURITY_ATTRIBUTES
sa.nLength = Len(sa)
si.cb = Len(si)
code = CreateProcess('D:WINNTSYSTEM32calc.exe', vbNullString, sa, sa, 0, NORMAL_PRIORITY_CLASS, vbNullString, vbNullString, si, info)
If info.hProcess <> 0 Then
code = STILL_ACTIVE
Do While code = STILL_ACTIVE
GetExitCodeProcess info.hProcess, code
Loop
End If
End Sub