主  题:commondialog控件是否可以一次选取多个文件?是用什么属性或者什么方法?请写出具体代码来。
作  者:yuanyiok
所属论坛:Visual Basic
问题点数:20
回复次数:3
发表时间:2001-8-20 9:58:12
 
  
   
回复贴子: 
回复人: ozw(沧浪客) (2001-8-20 10:08:27)  得0分 
.Flags = cdlOFNAllowMultiselect  
回复人: ozw(沧浪客) (2001-8-20 10:09:26)  得0分 
最好是
.Flags = cdlOFNAllowMultiselect And cdlOFNExplorer  
回复人: ozw(沧浪客) (2001-8-20 10:10:26)  得0分 
上面错了
.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer  
先找到一个,

解决方案 »

  1.   

    可以设置Flags属性为cdlOFNAllowMultiselect,然后再调用ShowOpen方法
    具体的属性还有很多。可以详细参考msdn
      

  2.   

    复人:JYQing(极于情) (2001-4-28 22:45:00)  得0分 
    Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As LongPublic Const OFN_READONLY = &H1
    Public Const OFN_ALLOWMULTISELECT = &H200
    Public Const OFN_EXPLORER = &H80000Type 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
    '************************************
    Dim m_ofn As OPENFILENAME
    With m_ofn
            .lStructSize = Len(m_ofn)
            .hInstance = App.hInstance
            .hwndOwner = Me.hwnd
            .lpstrFilter = "图片(*.BMP,*.JPG,*.GIF)" + Chr$(0) + "*.BMP;*.Jpg;*.Gif" + Chr$(0)
            .lpstrFileTitle = Space(254)
            .lpstrTitle = "添加图片..."
            .lpstrInitialDir = CurDir
            .lpstrFile = Space$(32000)  '这里设一个较大的数,可以返回超过长度256的文件名总和
            .nMaxFile = 32000
            .nMaxFileTitle = 255
            .flags = OFN_EXPLORER Or OFN_ALLOWMULTISELECT
        End With
        Dim i As Integer
        Dim Y As Integer
        Dim Z As Integer
        Dim FileNames$()
        
    Dim b As Long
            b = GetOpenFileName(m_ofn)
            If b = 1 Then
                m_ofn.lpstrFile = m_ofn.lpstrFile & Chr(0)
        Z = 1
    For i = 1 To Len(m_ofn.lpstrFile)
        i = InStr(Z, m_ofn.lpstrFile, Chr(0))
        If i = 0 Then Exit For
        ReDim Preserve FileNames(Y)
        FileNames(Y) = Mid(m_ofn.lpstrFile, Z, i - Z)
        Z = i + 1
        Y = Y + 1
    Next
            End If  
     回复人:Un1() (2001-4-28 23:03:00)  得0分 
    这个不行吗:
    Me.CommonDialog1.Flags = cdlOFNAllowMultiselect
    Me.CommonDialog1.showopen
     
     回复人:fulaoxiao(米米) (2001-4-28 23:50:00)  得0分 
    Un1的方法当然可以。
    短文件名用 空格割开,长文件用\0分隔  
     回复人:QQRN(笨QQ) (2001-4-29 14:48:00)  得0分 
    关注兼混分  
     回复人:westwin(westwin) (2001-4-29 17:09:00)  得0分 
    关注!  
     回复人:jlum99(闲人) (2001-4-29 18:27:00)  得0分 
    如果使用的是控件的话,有一个multiselect属性可以设置.  
     回复人:bucher(bucher) (2001-4-29 18:59:00)  得0分 
    MSDN里面有详细的解释  
     回复人:LIUYAOISH(LIUYAOISH) (2001-5-2 21:23:00)  得0分 
    看msdn.  
     回复人:Tenner(Tenner) (2001-5-3 15:18:00)  得0分 
    设置CommonDialog1.Flags = cdlOFNAllowMultiselect
    然后.showopen
    返回的文件名以chr(0)分界,第一个是路径,从第二个开始是所选的文件名
    如选的是c:\windows\abc.txt 和c:\windows\bcd.txt 则返回的字符串为
    "C:\windows" & chr(0) & "abc.txt" & chr(0) & "bcd.txt"
     
     回复人:huangguanshu() (2001-5-3 15:29:00)  得0分 
    Private Type DlgFileInfo
      iCount As Integer
      sPath As String
      sFile() As String
    End TypePrivate Function GetFileName(ByVal nFileName As String) As String
    Dim TMP As String, R As String, A As Integer
    TMP = nFileName
    Do
      A = InStr(TMP, "\")
      If A = 0 Then
      GetFileName = TMP
      Exit Do
      End If
      R = Mid(TMP, A + 1)
      TMP = R
    Loop
    End FunctionPrivate Function GetSelFile(ByVal strFilename As String) As DlgFileInfo
    Dim Fn() As String, Path As String, i As Integer
    Fn = Split(strFilename, vbNullChar)
    GetSelFile.iCount = UBound(Fn)
    If UBound(Fn) = 0 Then
      GetSelFile.iCount = 1
      ReDim GetSelFile.sFile(0)
      GetSelFile.sFile(0) = GetFileName(strFilename)
      GetSelFile.sPath = Left$(strFilename, Len(strFilename) - Len(GetSelFile.sFile(0)))
    Else
      ReDim GetSelFile.sFile(UBound(Fn) - 1)
      For i = 0 To UBound(Fn) - 1
        GetSelFile.sFile(i) = Fn(i + 1)
      Next i
      Path = Fn(0)
      If Right$(Path, 1) <> "\" Then
        GetSelFile.sPath = Path & "\"
      Else
        GetSelFile.sPath = Path
      End If
    End If
    End Functiondim selfile as DlgFileInfo
    cdg.showopen 'cdg是公共对话框控件。
    selfile  = GetSelFile(cdg.filename)
    其中 iCount 是返回打开文件的总数,sPath 返回路径,sFile() 返回文件名。
     
      

  3.   

    klaaa(klaaa) (2001-5-12 0:35:00)  得0分 
    设置CommonDialog控件的属性为
    cdlOFNAllowMultiselect Or cdlOFNPathMustExist Or cdlOFNFileMustExist
    即可选择打开多个文件
    然后FileName属性返回所有文件名,是用空格隔开的  
     回复人:klaaa(klaaa) (2001-5-12 2:44:00)  得0分 
    设置CommonDialog控件的Flags属性为
    cdlOFNAllowMultiselect Or cdlOFNPathMustExist Or cdlOFNFileMustExist  
     回复人:hypmonkey(一平) (2001-5-12 8:14:00)  得0分 
      VB提供的对话框可提供多文件提取,我这有段程序:
    一。    
          CommonDialog1.Flags = &H200&
          CommonDialog1.Action = 1
          CommonDialog1.filename = CommonDialog1.filename & Chr(32)
          z = 1
          For i = 1 To Len(CommonDialog1.filename)
              i = InStr(z, CommonDialog1.filename, Chr(32))
              If i = 0 Then Exit For
              ReDim Preserve file(y)
              file(y) = Mid(CommonDialog1.filename, z, i - z)
              z = i + 1
              If y = 0 Then
                  cpath = file(0)
      '第一行为目录
              endif
              y = y + 1
          Next
    二。
      Function SelectMultipleFiles(CD As CommonDialog, Filter As String, Filenames() As String) As Boolean
          On Error GoTo ExitNow
          CD.Filter = "All files (*.*)&brvbar;*.*&brvbar;" & Filter
          CD.FilterIndex = 1
          CD.Flags = cdlOFNAllowMultiselect Or cdlOFNFileMustExist Or cdlOFNExplorer
          CD.DialogTitle = "Select one or more files"
          CD.MaxFileSize = 10240
          CD.FileName = ""
          CD.CancelError = True
          CD.ShowOpen
          Filenames() = Split(CD.FileName, vbNullChar)
          SelectMultipleFiles = True
      ExitNow:
      End Function