VB中一个命令按钮调用shell函数打开外部程序后,该命令按钮失效,外部...
发布网友
发布时间:2024-05-28 13:19
我来回答
共1个回答
热心网友
时间:2024-05-31 21:05
运行后得到PID值,然后判断PID值关闭即可。
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 Const INFINITE = -1&
Private Const SYNCHRONIZE = &H100000
Private Sub Command1_Click()
Command1.Enabled = False
Dim i As Long
Dim r As Long
Dim p As Long
i = Shell("notepad.exe", vbNormalFocus)
p = OpenProcess(SYNCHRONIZE, False, i)
r = WaitForSingleObject(p, INFINITE)
r = CloseHandle(p)
Command1.Enabled = True
End Sub