vb中的通用对话框的filename返回的为什么是文件夹的路径
我设置对话框支持多选,然后filename属性返回的是文件夹的路径,如果是单选它能返回文件的路径。(源码)...
我设置对话框支持多选,然后filename属性返回的是文件夹的路径,如果是单选它能返回文件的路径。
(源码) 展开
(源码) 展开
3个回答
展开全部
'注意,在模块中
'***********************************************************************
'在此为打开文件
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Declare Function GetFileTitle Lib "comdlg32.dll" Alias "GetFileTitleA" (ByVal lpszFile As String, ByVal lpszTitle As String, ByVal cbBuf As Integer) As Integer
'设置OPENFILENAME类所包含的属性值
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 Const OFN_READONLY = &H1
Public Const OFN_OVERWRITEPROMPT = &H2
Public Const OFN_HIDEREADONLY = &H4
Public Const OFN_NOCHANGEDIR = &H8
Public Const OFN_SHOWHELP = &H10
Public Const OFN_ENABLEHOOK = &判带樱H20
Public Const OFN_ENABLETEMPLATE = &H40
Public Const OFN_ENABLETEMPLATEHANDLE = &H80
Public Const OFN_NOVALIDATE = &H100
Public Const OFN_ALLOWMULTISELECT = &H200
Public Const OFN_EXTENSIONDIFFERENT = &H400
Public Const OFN_PATHMUSTEXIST = &H800
Public Const OFN_FILEMUSTEXIST = &H1000
Public Const OFN_CREATEPROMPT = &H2000
Public Const OFN_SHAREAWARE = &H4000
Public Const OFN_NOREADONLYRETURN = &H8000
Public Const OFN_NOTESTFILECREATE = &行丛H10000
Public Const OFN_NONETWORKBUTTON = &H20000
Public Const OFN_NOLONGNAMES = &H40000 ' force no long names for 4.x modules
Public Const OFN_EXPLORER = &H80000 ' new look commdlg
Public Const OFN_NODEREFERENCELINKS = &H100000
Public Const OFN_LONGNAMES = &H200000 ' force long names for 3.x modules
Public Const OFN_SHAREFALLTHROUGH = 2
Public Const OFN_SHARENOWARN = 1
Public Const OFN_SHAREWARN = 0
'*************************************************************************
Public Function loofile1()
'可以选择多个文件
'当选择一个文件时 缓冲区填充 :文件& chr(0)&chr(0)..
'当选择多个文件时 缓冲区填充 :文件夹& chr(0)&文件名1 &chr(0)&文件名2 &chr(0)..
Dim ofn As OPENFILENAME
Dim rtn As String
ofn.lStructSize = Len(ofn)
ofn.hwndOwner = Menu.hwnd
ofn.hInstance = App.hInstance
ofn.lpstrFilter = "音频文件" & Chr(0) & "*.mid;*.wma;*.wav;*.mp3;*.ogg" & _
Chr(0) & "视频文件" & Chr(0) & "*.RM;*.RMVB;*.DAT;*.ASF;*.MPG;*.AVI" & _
Chr(0) & "所有文件" & Chr(0) & "*.*" & Chr(0) & Chr(0)
'"所有文件" & Chr(0) & "*.*" & Chr(0)
ofn.lpstrFile = String$(250, 0)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = String$(250, 0)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = App.Path
ofn.lpstrTitle = "打开文件"
ofn.Flags = OFN_ALLOWMULTISELECT Or OFN_EXPLORER Or OFN_NODEREFERENCELINKS Or OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST
If GetOpenFileName(ofn) <> 0 Then loofile1 = ofn.lpstrFile
End Function
'*************************************************************************
'处理方法:
myfilemu = loofile1()
If myfilemu = "" Then Exit Sub '如果按取消 就退出过程
a = Split(myfilemu, Chr(0))
If a(1) <> "" Then '选择了多个文件
For i = 1 To UBound(a)
If Right(a(0), 1) = "\" Then
myfilepick = a(0) & a(i)
Else '添加文件的完整路径到隐藏列表中
myfilepick = a(0) & "\" & a(i)
End If
debug.print myfilepick
Next i
Else '选择了一个文件
myfilepick = Left(myfilemu, InStr(myfilemu, Chr(0)) - 1)
debug.print myfilepick
End If
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询