📄 form1.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1
Caption = "带历史信息的菜单"
ClientHeight = 1665
ClientLeft = 2280
ClientTop = 3060
ClientWidth = 3750
LinkTopic = "Form1"
PaletteMode = 1 'UseZOrder
ScaleHeight = 1665
ScaleWidth = 3750
StartUpPosition = 1 '所有者中心
Begin VB.CommandButton Command2
Caption = "退出"
Height = 465
Left = 1890
TabIndex = 1
Top = 990
Width = 1380
End
Begin VB.CommandButton Command1
Caption = "清除历史菜单"
Height = 465
Left = 420
TabIndex = 0
Top = 990
Width = 1380
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 2880
Top = 270
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.Menu mnuFile
Caption = "文件(&F)"
Begin VB.Menu open
Caption = "打开文件"
End
Begin VB.Menu mnuFilelist
Caption = "-"
Index = 0
End
Begin VB.Menu line
Caption = "-"
End
Begin VB.Menu exit
Caption = "退出"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private max_index As Integer
Dim myindex As Integer
Private Sub Form_Activate()
Dim file As Long
Dim mystring As String
Dim s As String
Dim strfilename As String
strfilename = App.Path & "\cdxx.ini"
file = FreeFile()
On Error Resume Next
Open strfilename For Input As #file '打开文件菜单列表
Do While Not EOF(file)
Line Input #file, mystring
If mystring <> "" Then
max_index = max_index + 1
Load mnuFilelist(max_index)
mnuFilelist(max_index).Caption = mystring
mnuFilelist(max_index).Visible = True
End If
Loop
Close #file '关闭文件菜单列表
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim FNum As Integer
Dim strfilename As String
Dim i As Integer
FNum = FreeFile
strfilename = App.Path & "\cdxx.ini"
If Dir(strfilename) <> "" Then Kill strfilename
Open strfilename For Output As #FNum
For i = 1 To mnuFilelist.Count - 1
Print #FNum, mnuFilelist(i).Caption
Next
Close #FNum
Exit Sub
End Sub
Private Sub open_Click() '打开文件菜单
On Error Resume Next
CommonDialog1.CancelError = True
CommonDialog1.DialogTitle = "打开文件"
CommonDialog1.FileName = ""
CommonDialog1.Filter = "Executables(*.*)|*.*"
CommonDialog1.FilterIndex = 1
CommonDialog1.Flags = cdlOFNCreatePrompt + cdlOFNHideReadOnly
CommonDialog1.ShowOpen
max_index = mnuFilelist.Count
Load mnuFilelist(max_index)
mnuFilelist(max_index).Caption = CommonDialog1.FileName
mnuFilelist(max_index).Visible = True
End Sub
Private Sub exit_Click()
Dim FNum As Integer
Dim strfilename As String
Dim i As Integer
FNum = FreeFile
strfilename = App.Path & "\cdxx.ini"
If Dir(strfilename) <> "" Then Kill strfilename
Open strfilename For Output As #FNum
For i = 1 To mnuFilelist.Count - 1
Print #FNum, mnuFilelist(i).Caption
Next
Close #FNum
End
End Sub
Private Sub Command1_Click() '清除菜单历史信息
Dim i As Integer
For i = 1 To mnuFilelist.Count - 1
Unload mnuFilelist(i)
Next i
End Sub
Private Sub Command2_Click()
Dim FNum As Integer
Dim strfilename As String
Dim i As Integer
FNum = FreeFile
strfilename = App.Path & "\cdxx.ini"
If Dir(strfilename) <> "" Then Kill strfilename '删除文件
Open strfilename For Output As #FNum
For i = 1 To mnuFilelist.Count - 1
Print #FNum, mnuFilelist(i).Caption '按打开文件的顺序写入文件
Next
Close #FNum
End
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -