📄 modshell.bas
字号:
Attribute VB_Name = "modShell"
Option Explicit
Public Const INFINITE As Long = -1&
Public Const STATUS_WAIT_0 As Long = &H0
Public Const WAIT_OBJECT_0 As Long = STATUS_WAIT_0
Public Const NORMAL_PRIORITY_CLASS As Long = &H20&
Public Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
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
Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
nReserved1 As Integer
nReserved2 As Integer
szPathName As String * 256
End Type
Declare Function WaitForSingleObject Lib "Kernel32" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
Declare Function InputIdle Lib "user32" Alias "WaitForInputIdle" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
Declare Function CreateProcessA Lib "Kernel32" (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
Declare Function CloseHandle Lib "Kernel32" (ByVal hObject As Long) As Long
''==============================================================================
''Code flow routines:
Public Function SyncShell(CommandLine As String, Optional Timeout As Long, _
Optional WaitForInputIdle As Boolean, Optional Hide As Boolean = False) As Boolean
On Error GoTo ErrHandle
Dim hProcess As Long
Const STARTF_USESHOWWINDOW As Long = &H1
Const SW_HIDE As Long = 0
Dim ret As Long
Dim nMilliseconds As Long
If Timeout > 0 Then
nMilliseconds = Timeout
Else
nMilliseconds = INFINITE
End If
hProcess = StartProcess(CommandLine, Hide)
If WaitForInputIdle Then
'Wait for the shelled application to finish setting up its UI:
ret = InputIdle(hProcess, nMilliseconds)
Else
'Wait for the shelled application to terminate:
ret = WaitForSingleObject(hProcess, nMilliseconds)
End If
CloseHandle hProcess
''''''''''''''''''''''''''''' lcw 1999.8.18 '''
Dim iFor As Integer
For iFor = 1 To 1000
DoEvents
Next ''''''''''''''''''''''''''''' lcw '''
'Return True if the application finished. Otherwise it timed out or erred.
SyncShell = (ret = WAIT_OBJECT_0)
Exit Function
ErrHandle:
MsgBox "压缩、解压缩文件出错!", vbOKOnly + vbInformation, "提示信息"
End Function
Public Function StartProcess(CommandLine As String, Optional Hide As Boolean = False) As Long
On Error GoTo ErrHandle
Const STARTF_USESHOWWINDOW As Long = &H1
Const SW_HIDE As Long = 0
Dim proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO
'Initialize the STARTUPINFO structure:
Start.cb = Len(Start)
If Hide Then
Start.dwFlags = STARTF_USESHOWWINDOW
Start.wShowWindow = SW_HIDE
End If
'Start the shelled application:
CreateProcessA 0&, CommandLine, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, Start, proc
StartProcess = proc.hProcess
Exit Function
ErrHandle:
MsgBox "压缩、解压缩文件出错!", vbOKOnly + vbInformation, "提示信息"
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -