在一个无边框的窗体的有一个winsock控件,当winscok控件收到一个字符"s"时,调用shell运行一个可执行文件,例如一个flash演示,这个演示为当前窗口,而刚才无边框的窗口为后台.shell这个flash演示,在这个演示过程中不管winsock收到什么,也都在这个flash演示中,只有到这个flash演示结束,才回到无边框的窗口,现在问题是只要winsock不管接收到什么,这个无边框的窗口就弹出来变成当前窗口,而flash还没有演示完呢.
我用以下处理也不行,模块中定义以下api
Declare Function OpenProcess Lib ″kernel32″ Alias ″OpenProcess″ (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Declare Function CloseHandle Lib ″kernel32″ Alias ″CloseHandle″ (ByVal hObject As Long) As Long 窗体中的代码
Dim RetVal As Long
Private Sub Command1_Click()
RetVal = Shell("C:\WINDOWS\aaa.EXE", 1)
Me.WindowState = 1
me.hide
Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
hProgram=OpenProcess(0,False,RetVal)
If hProgram=0 Then
Me.WindowState = 2
me.show
End If
End Sub
我用以下处理也不行,模块中定义以下api
Declare Function OpenProcess Lib ″kernel32″ Alias ″OpenProcess″ (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Declare Function CloseHandle Lib ″kernel32″ Alias ″CloseHandle″ (ByVal hObject As Long) As Long 窗体中的代码
Dim RetVal As Long
Private Sub Command1_Click()
RetVal = Shell("C:\WINDOWS\aaa.EXE", 1)
Me.WindowState = 1
me.hide
Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
hProgram=OpenProcess(0,False,RetVal)
If hProgram=0 Then
Me.WindowState = 2
me.show
End If
End Sub
On Error Resume Next
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim s As String, t As String
Dim tmpFileName As String
Dim i As Integer
Dim ret As Long
start.cb = Len(start)
For i = LBound(FileName) To UBound(FileName)
If tmpFileName = "" Then
tmpFileName = FileName(i)
Else
tmpFileName = tmpFileName & " " & FileName(i)
End If
Next
s = MyAppPath & "UPLOAD.exe -p1 -b19200 -i123456 -s " & tmpFileName
ret& = CreateProcessA(vbNullString, s, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, ExitCode)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
If ExitCode = 0 Then '等于0,正常接收文件
SendTxt = True
Else
SendTxt = False
End If
End Function
参考一下,相应的API的常量自已找一下吧.
这段代码就是等待调用的程序被关闭后,才继续向下执行