用的精简版vb6?
像common dialog这样几乎所有ms系统中都会带有的东西,用api更好,免得在发布时还要带上一个OCX。
程序代码:
Option Explicit
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Const OFN_PATHMUSTEXIST = &H800 '路径必须存在
Private Const OFN_FILEMUSTEXIST = &H1000 '文件必须存在
'' OPENFILENAME 结构的元素顺序必须按vb6自带的api浏览器里的格式声明。按foxApi V1.5里的声明时出错
Private Type OPENFILENAME
lStructSize As Long
hwndOwner 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
Public Function ShowOpen(ByVal hwndOwner As Long, Optional ByVal strTitle As String = "打开...", Optional ByVal lpstrFilter As String = "All Files(*.*)" & vbNullChar & "*.*" & vbNullChar, Optional ByVal initDir As String = "c:\", Optional ByVal defExt As String = "*.JTF") As String
On Error Resume Next
Dim OFName As OPENFILENAME
OFName.lStructSize = Len(OFName)
OFName.hwndOwner = hwndOwner
OFName.lpstrFilter = lpstrFilter
OFName.lpstrFile = Space$(254)
OFName.nMaxFile = 255
OFName.lpstrFileTitle = Space$(254)
OFName.nMaxFileTitle = 255
OFName.lpstrInitialDir = initDir
OFName.lpstrTitle = strTitle
OFName.lpstrDefExt = defExt
OFName.flags = OFN_FILEMUSTEXIST Or OFN_PATHMUSTEXIST
'Debug.Print OFName.nFileExtension
If GetOpenFileName(OFName) Then
ShowOpen = Trim$(OFName.lpstrFile)
Else
ShowOpen = ""
End If
End Function