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
Dim pID As Long
Function StillRun(ByVal ProgramID) As Boolean
Dim lHProgram As Long
Dim lReturn As Long
hProgram = OpenProcess(0, False, ProgramID)
If Not hProgram = 0 Then
StillRun = True
Else
StillRun = False
End If
CloseHandle hProgram
End Function
Private Sub Form_Load()
If Dir$("c:\windows\cdplayer.exe") <> "" Then
Me.Show
pID = Shell("c:\windows\cdplayer.exe")
While StillRun(pID)
DoEvents
Wend
End
Else
MsgBox "没有找到CD播放器"
End
End If
End Sub
谢谢kissoflife,我给据你的做法,稍加改动撮成功了,
如下:
在一般模块中:
Public Const SYNCHRONIZE = &H100000
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
具体运用:
Dim pID As Long, pHnd As Long ' 分别声明 Process Id 及 Process Handle 变数
pID = Shell(App.Path + "\WENNER.exe", 1)
II = MsgBox(" 提示:正在运行,DOS窗口结束后按回车键 ...", 0, " 运行接地电阻计算程序")
StillRun1 = True
While StillRun1
pHnd = OpenProcess(SYNCHRONIZE, 0, pID)
If pHnd <> 0 Then
StillRun1 = True
Else
StillRun1 = False
End If
CloseHandle pHnd
Wend