📄 form1.frm
字号:
VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Begin VB.Form Form1
Caption = "执行DOS命令并回显执行结果"
ClientHeight = 7680
ClientLeft = 60
ClientTop = 345
ClientWidth = 9825
LinkTopic = "Form1"
LockControls = -1 'True
ScaleHeight = 7680
ScaleWidth = 9825
StartUpPosition = 2 '屏幕中心
Begin VB.Frame Frame1
Height = 825
Left = 90
TabIndex = 1
Top = 6750
Width = 9645
Begin VB.CommandButton Command3
Caption = "清空文本内容(&C)"
Height = 375
Left = 7890
TabIndex = 2
Top = 270
Width = 1545
End
Begin VB.CommandButton Command2
Caption = "(&A)PI管道方式"
Height = 375
Left = 6570
TabIndex = 3
Top = 270
Width = 1335
End
Begin VB.CommandButton Command1
Caption = "(&S)hell方式"
Height = 375
Left = 5370
TabIndex = 5
Top = 270
Width = 1215
End
Begin VB.TextBox Text1
Height = 345
Left = 900
TabIndex = 4
Text = "CMD /C Dir C:\"
Top = 285
Width = 4275
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "命令行:"
Height = 180
Left = 150
TabIndex = 6
Top = 360
Width = 630
End
End
Begin RichTextLib.RichTextBox RichTextBox1
Height = 6615
Left = 60
TabIndex = 0
Top = 90
Width = 9705
_ExtentX = 17119
_ExtentY = 11668
_Version = 393217
ReadOnly = -1 'True
ScrollBars = 3
AutoVerbMenu = -1 'True
TextRTF = $"Form1.frx":0000
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim StartDateTime As Long
Const SplitLength As Integer = 60
Private Sub Command1_Click()
StartDateTime = GetTickCount()
CommandEnable False
Me.Caption = "正在执行命令..."
RichTextBox1.SelColor = QBColor(8)
RichTextBox1.SelText = String(SplitLength, "#") & vbCrLf & " 以Shell方式执行DOS命令的返回结果:" & vbCrLf & String(SplitLength, "-") & vbCrLf
RichTextBox1.SelColor = QBColor(0)
RichTextBox1.SelText = ExeCMD(Text1.Text)
RichTextBox1.SelColor = QBColor(8)
RichTextBox1.SelText = String(SplitLength, "-") & vbCrLf & " 执行完毕 " & Now() & " 花费时间: " & FormatNumber(GetTickCount() - StartDateTime, 0, True) & " 毫秒" & vbCrLf & String(SplitLength, "-") & vbCrLf
Me.Caption = " 执行完毕 " & Now() & " 花费时间: " & FormatNumber(GetTickCount() - StartDateTime, 0, True) & " 毫秒"
CommandEnable True
End Sub
Private Sub Command2_Click()
StartDateTime = GetTickCount()
CommandEnable False
Me.Caption = "正在执行命令..."
RichTextBox1.SelColor = QBColor(8)
RichTextBox1.SelText = String(SplitLength, "*") & vbCrLf & " 以管道方式执行DOS命令的返回结果:" & vbCrLf & String(SplitLength, "-") & vbCrLf
RichTextBox1.SelColor = QBColor(0)
RichTextBox1.SelText = ExecuteCommand(Text1.Text)
RichTextBox1.SelColor = QBColor(8)
RichTextBox1.SelText = String(SplitLength, "-") & vbCrLf & " 执行完毕 " & Now() & " 花费时间: " & FormatNumber(GetTickCount() - StartDateTime, 0, True) & " 毫秒" & vbCrLf & String(SplitLength, "-") & vbCrLf
Me.Caption = " 执行完毕 " & Now() & " 花费时间: " & FormatNumber(GetTickCount() - StartDateTime, 0, True) & " 毫秒"
CommandEnable True
End Sub
Private Sub Command3_Click()
RichTextBox1 = ""
End Sub
Private Sub Form_Resize()
If Me.WindowState <> vbMinimized Then
RichTextBox1.Width = Me.ScaleWidth - RichTextBox1.Left * 2
RichTextBox1.Height = Me.ScaleHeight - RichTextBox1.Top * 3 - Frame1.Height + 60
Frame1.Top = Me.ScaleHeight - Frame1.Height - RichTextBox1.Top
End If
End Sub
Sub CommandEnable(EE As Boolean)
Command1.Enabled = EE
Command2.Enabled = EE
Command3.Enabled = EE
Text1.Enabled = EE
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -