保存为.frm文件 VERSION 5.00 Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX" Begin VB.Form Form1 Caption = "Form1" ClientHeight = 3090 ClientLeft = 60 ClientTop = 450 ClientWidth = 4680 LinkTopic = "Form1" ScaleHeight = 3090 ScaleWidth = 4680 StartUpPosition = 3 '窗口缺省 Begin MSComDlg.CommonDialog CommonDialog1 Left = 3840 Top = 2280 _ExtentX = 847 _ExtentY = 847 _Version = 393216 End Begin VB.CommandButton Command2 Caption = "删除" Height = 375 Left = 3120 TabIndex = 2 Top = 720 Width = 1215 End Begin VB.CommandButton Command1 Caption = "添加" Height = 375 Left = 3120 TabIndex = 1 Top = 240 Width = 1215 End Begin VB.ListBox List1 Height = 2400 Left = 240 TabIndex = 0 Top = 240 Width = 2535 End Begin VB.Label Label1 Caption = "双击打开" Height = 375 Left = 3120 TabIndex = 3 Top = 1320 Width = 1335 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPrivate Sub Command1_Click()CommonDialog1.Filter = "所有文件|*.*" CommonDialog1.ShowOpen If CommonDialog1.FileName <> "" Then List1.AddItem CommonDialog1.FileNameEnd SubPrivate Sub Command2_Click() If List1.ListIndex <> -1 Then List1.RemoveItem List1.ListIndex End SubPrivate Sub List1_DblClick() ShellExecute hwnd, "open", List1.List(List1.ListIndex), vbNullString, vbNullString, 1 End Sub
如果有错,改用这个: VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 3090 ClientLeft = 60 ClientTop = 450 ClientWidth = 4680 LinkTopic = "Form1" ScaleHeight = 3090 ScaleWidth = 4680 StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command2 Caption = "删除" Height = 375 Left = 3120 TabIndex = 2 Top = 720 Width = 1215 End Begin VB.CommandButton Command1 Caption = "添加" Height = 375 Left = 3120 TabIndex = 1 Top = 240 Width = 1215 End Begin VB.ListBox List1 Height = 2400 Left = 240 TabIndex = 0 Top = 240 Width = 2535 End Begin VB.Label Label1 Caption = "双击打开" Height = 375 Left = 3120 TabIndex = 3 Top = 1320 Width = 1335 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPrivate Const OFN_FILEMUSTEXIST = &H1000 Private Const OFN_HIDEREADONLY = &H4 Private Const OFN_OVERWRITEPROMPT = &H2 Private Const OFN_PATHMUSTEXIST = &H800Private Type OPENFILENAME lStructSize As Long hwnd As Long hInstance As Long lpstrFilter As String lpstrCustomFilter As String nMaxCustFilter As Long nFilterIndex As Long lpstrFile As String nMaxFile As Long lpstrFileTitle As String nMaxFileTitle As Long lpstrInitialDir As String lpstrTitle As String Flags As Long nFileOffset As Integer nFileExtension As Integer lpstrDefExt As String lCustData As Long lpfnHook As Long lpTemplateName As String End Type'[API函数]:显示打开保存对话框 Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long'[函数]:显示打开保存对话框 Private Function DialogFile(hwnd As Long, wMode As Integer, szDialogTitle As String, szFilename As String, szFilter As String, szDefDir As String, szDefExt As String) As String Dim x As Long, OFN As OPENFILENAME, szFile As String, szFileTitle As String OFN.lStructSize = Len(OFN) OFN.hwnd = hwnd OFN.lpstrTitle = szDialogTitle OFN.lpstrFile = szFilename & String$(250 - Len(szFilename), 0) OFN.nMaxFile = 255 OFN.lpstrFileTitle = String$(255, 0) OFN.nMaxFileTitle = 255 OFN.lpstrFilter = szFilter OFN.nFilterIndex = 1 OFN.lpstrInitialDir = szDefDir OFN.lpstrDefExt = szDefExt If wMode = 1 Then OFN.Flags = OFN_HIDEREADONLY Or OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST x = GetOpenFileName(OFN) Else OFN.Flags = OFN_HIDEREADONLY Or OFN_OVERWRITEPROMPT Or OFN_PATHMUSTEXIST x = GetSaveFileName(OFN) End If If x <> 0 Then If InStr(OFN.lpstrFile, Chr$(0)) > 0 Then szFile = Left$(OFN.lpstrFile, InStr(OFN.lpstrFile, Chr$(0)) - 1) End If DialogFile = szFile Else DialogFile = "" End If End FunctionPrivate Sub Command1_Click() Dim filename As String filename = DialogFile(hwnd, 1, "打开", "", "所有文件" & Chr(0) & "*.*", "", "") If filename <> "" Then List1.AddItem filenameEnd SubPrivate Sub Command2_Click() If List1.ListIndex <> -1 Then List1.RemoveItem List1.ListIndex End SubPrivate Sub List1_DblClick() ShellExecute hwnd, "open", List1.List(List1.ListIndex), vbNullString, vbNullString, 1 End Sub
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPrivate Sub Command2_Click() If List1.ListIndex <> -1 Then List1.RemoveItem List1.ListIndex End SubPrivate Sub Command3_Click() Dim s As String '首先 要从工程 部件 中选择加载 Microsoft Common Dialog Control 6.0 Me.CommonDialog1.DialogTitle = "open file" Me.CommonDialog1.Filter = "bmp files(*.bmp)|*.bmp|jpg files(*.jpg)|*.jpg|all files(*.*)|*.*" Me.CommonDialog1.ShowOpen s = Me.CommonDialog1.FileName
List1.AddItem s 'Picture1.Picture = LoadPicture(Me.CommonDialog1.FileName) End SubPrivate Sub List1_DblClick() ShellExecute Me.hwnd, "open", List1.List(List1.ListIndex), vbNullString, vbNullString, 1 End Sub
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin MSComDlg.CommonDialog CommonDialog1
Left = 3840
Top = 2280
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.CommandButton Command2
Caption = "删除"
Height = 375
Left = 3120
TabIndex = 2
Top = 720
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "添加"
Height = 375
Left = 3120
TabIndex = 1
Top = 240
Width = 1215
End
Begin VB.ListBox List1
Height = 2400
Left = 240
TabIndex = 0
Top = 240
Width = 2535
End
Begin VB.Label Label1
Caption = "双击打开"
Height = 375
Left = 3120
TabIndex = 3
Top = 1320
Width = 1335
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPrivate Sub Command1_Click()CommonDialog1.Filter = "所有文件|*.*"
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then List1.AddItem CommonDialog1.FileNameEnd SubPrivate Sub Command2_Click()
If List1.ListIndex <> -1 Then List1.RemoveItem List1.ListIndex
End SubPrivate Sub List1_DblClick()
ShellExecute hwnd, "open", List1.List(List1.ListIndex), vbNullString, vbNullString, 1
End Sub
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "删除"
Height = 375
Left = 3120
TabIndex = 2
Top = 720
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "添加"
Height = 375
Left = 3120
TabIndex = 1
Top = 240
Width = 1215
End
Begin VB.ListBox List1
Height = 2400
Left = 240
TabIndex = 0
Top = 240
Width = 2535
End
Begin VB.Label Label1
Caption = "双击打开"
Height = 375
Left = 3120
TabIndex = 3
Top = 1320
Width = 1335
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPrivate Const OFN_FILEMUSTEXIST = &H1000
Private Const OFN_HIDEREADONLY = &H4
Private Const OFN_OVERWRITEPROMPT = &H2
Private Const OFN_PATHMUSTEXIST = &H800Private Type OPENFILENAME
lStructSize As Long
hwnd As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type'[API函数]:显示打开保存对话框
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long'[函数]:显示打开保存对话框
Private Function DialogFile(hwnd As Long, wMode As Integer, szDialogTitle As String, szFilename As String, szFilter As String, szDefDir As String, szDefExt As String) As String
Dim x As Long, OFN As OPENFILENAME, szFile As String, szFileTitle As String
OFN.lStructSize = Len(OFN)
OFN.hwnd = hwnd
OFN.lpstrTitle = szDialogTitle
OFN.lpstrFile = szFilename & String$(250 - Len(szFilename), 0)
OFN.nMaxFile = 255
OFN.lpstrFileTitle = String$(255, 0)
OFN.nMaxFileTitle = 255
OFN.lpstrFilter = szFilter
OFN.nFilterIndex = 1
OFN.lpstrInitialDir = szDefDir
OFN.lpstrDefExt = szDefExt
If wMode = 1 Then
OFN.Flags = OFN_HIDEREADONLY Or OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST
x = GetOpenFileName(OFN)
Else
OFN.Flags = OFN_HIDEREADONLY Or OFN_OVERWRITEPROMPT Or OFN_PATHMUSTEXIST
x = GetSaveFileName(OFN)
End If
If x <> 0 Then
If InStr(OFN.lpstrFile, Chr$(0)) > 0 Then
szFile = Left$(OFN.lpstrFile, InStr(OFN.lpstrFile, Chr$(0)) - 1)
End If
DialogFile = szFile
Else
DialogFile = ""
End If
End FunctionPrivate Sub Command1_Click()
Dim filename As String
filename = DialogFile(hwnd, 1, "打开", "", "所有文件" & Chr(0) & "*.*", "", "")
If filename <> "" Then List1.AddItem filenameEnd SubPrivate Sub Command2_Click()
If List1.ListIndex <> -1 Then List1.RemoveItem List1.ListIndex
End SubPrivate Sub List1_DblClick()
ShellExecute hwnd, "open", List1.List(List1.ListIndex), vbNullString, vbNullString, 1
End Sub
If List1.ListIndex <> -1 Then List1.RemoveItem List1.ListIndex
End SubPrivate Sub Command3_Click()
Dim s As String
'首先 要从工程 部件 中选择加载 Microsoft Common Dialog Control 6.0
Me.CommonDialog1.DialogTitle = "open file"
Me.CommonDialog1.Filter = "bmp files(*.bmp)|*.bmp|jpg files(*.jpg)|*.jpg|all files(*.*)|*.*"
Me.CommonDialog1.ShowOpen
s = Me.CommonDialog1.FileName
List1.AddItem s
'Picture1.Picture = LoadPicture(Me.CommonDialog1.FileName)
End SubPrivate Sub List1_DblClick()
ShellExecute Me.hwnd, "open", List1.List(List1.ListIndex), vbNullString, vbNullString, 1
End Sub