1、启动VB6,确定后创建默认窗体Form1,将其name属性改为main_frm.
2、右边工程管理窗口的窗体上点击鼠标右键---》添加--》添加MDI窗体,将该窗体的name属性改为main.
3、将main_frm窗体的MDIChild属性设为true,让它成为main窗体的子窗体。
4、在main窗体中,点击VB菜单中的“工具”--》“菜单编辑器”,设置菜单项:
标题:文件 名称:file
点击下一个按钮,接着点击向右箭头
标题:打开 名称:open
点击下一个按钮
标题:关闭所有 名称:close
点击下一个按钮
标题:- 名称:mnufilelist 索引:0
点击下一个按钮
标题:- 名称:l
点击下一个按钮
标题:退出 名称:exit
5、工具箱上点右键,选“部件”,勾选“Microsoft Common Dialog Control 6.0(SP6)”,将该控件拖到main窗体
6、代码讲解
Option Explicit '变量必须声明
Dim main As New main_frm '子窗体实例
Public max_index As Integer '菜单项数目
Private Sub close_Click()
Dim FNum As Integer
Dim strfilename As String
Dim i As Integer
On Error Resume Next
For Each main In Forms '关闭所有打开的子窗体
If main.MDIChild = True Then
Unload main
End If
Next
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 '将打开的每个文件存入ini文件中
Next
Close #FNum
Exit Sub
End Sub
Private Sub exit_Click()
close_Click
End
End Sub
Private Sub MDIForm_Load()
Dim file As Long
Dim mystring 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 MDIForm_Unload(Cancel As Integer)
close_Click
End Sub
Private Sub mnufilelist_Click(Index As Integer)
If mnufilelist(Index).Caption <> "" Then
Static i As Integer
If i < 1 Then i = 1
main_frm.Visible = False
Dim main As New main_frm
main.Caption = mnufilelist(Index).Caption
i = i + 1
main.Picture = LoadPicture(mnufilelist(Index).Caption)
main.Show
End If
End Sub
Private Sub open_Click()
CommonDialog1.Filter = "所有图形文件|*.jpg;*.bmp;*.ico;*.gif;*.cur"
CommonDialog1.ShowOpen
Static i As Integer
If i < 1 Then i = 1
main_frm.Visible = False
Dim main As New main_frm
main.Caption = CommonDialog1.FileName
i = i + 1
main.Picture = LoadPicture(CommonDialog1.FileName)
main.Show
max_index = mnufilelist.Count
Load mnufilelist(max_index)
mnufilelist(max_index).Caption = CommonDialog1.FileName
mnufilelist(max_index).Visible = True
End Sub