Admin
27/09/2004, 16:05
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 Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Function SyncShell(ByVal cmdline As String, ByVal ShowApp As Boolean) As Boolean
'Const NORMAL_PRIORITY_CLASS = &H20
Const HIGH_PRIORITY_CLASS = &H80
'Const INFINITE = -1
'Const HIDE_WINDOW = 0
'Const SHOW_OPENWINDOW = 1
'Const SHOW_ICONWINDOW = 2
Const SHOW_FULLSCREEN = 3
'Const SHOW_OPENNOACTIVATE = 4
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
start.cb = Len(start)
start.dwFlags = IIf(ShowApp, 0, SHOW_FULLSCREEN)
If CreateProcess(0, cmdline, 0, 0, 1, HIGH_PRIORITY_CLASS, 0, 0, start, proc) = 1 Then
Do
DoEvents
Loop Until WaitForSingleObject(proc.hProcess, 0) <> 258
Call CloseHandle(proc.hProcess)
SyncShell = True
End If
End Function
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 Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Function SyncShell(ByVal cmdline As String, ByVal ShowApp As Boolean) As Boolean
'Const NORMAL_PRIORITY_CLASS = &H20
Const HIGH_PRIORITY_CLASS = &H80
'Const INFINITE = -1
'Const HIDE_WINDOW = 0
'Const SHOW_OPENWINDOW = 1
'Const SHOW_ICONWINDOW = 2
Const SHOW_FULLSCREEN = 3
'Const SHOW_OPENNOACTIVATE = 4
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
start.cb = Len(start)
start.dwFlags = IIf(ShowApp, 0, SHOW_FULLSCREEN)
If CreateProcess(0, cmdline, 0, 0, 1, HIGH_PRIORITY_CLASS, 0, 0, start, proc) = 1 Then
Do
DoEvents
Loop Until WaitForSingleObject(proc.hProcess, 0) <> 258
Call CloseHandle(proc.hProcess)
SyncShell = True
End If
End Function