怎么在vb下打开选择多个文件的对话框???我在编写程序的时候,使用了一个对话框控件来选择多个文件,但是这个控件比较老,好象是win95,98的,有没有最新的控件???请指教!

解决方案 »

  1.   

    在调用CommonDialog1.ShowOpen 前用以下语句设置
    CommonDialog1.flags = cdlOFNAllowMultiselect Or cdlOFNExplorerCommonDialog1.FileName 反回路径和文件名,每个文件名用空格格开.
      

  2.   

    用API函数打开多选文件对话框在模块中声明:
    Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As LongPublic 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 TypeCommand1_Click()事件中:
    Dim ofn As OPENFILENAME
    Dim FileName(50) As StringDim a As Long
    Dim i As Integer, j As Integer
    Dim tStr As String
    Dim FileNum  As Integerofn.lStructSize = Len(ofn)
    ofn.hwndOwner = Form1.hWnd
    ofn.hInstance = App.hInstance
    ofn.lpstrFilter = "所有文件" + Chr$(0) + "*.*"
    ofn.lpstrFile = Space$(500)
    ofn.nMaxFile = 600
    ofn.lpstrFileTitle = Space$(254)
    ofn.nMaxFileTitle = 255
    ofn.lpstrInitialDir = CurDir
    ofn.lpstrTitle = "打开"
    ofn.flags = &H200 Or &H80000 Or &H4a = GetOpenFileName(ofn)
    tStr = Trim$(ofn.lpstrFile)If (a) Then
        j = 1
        i = InStr(j, tStr, Chr(0))
        j = i + 1
        
        If i = 0 Then Exit Sub    FileName(0) = Mid(tStr, 1, i - 1)    For i = 1 To Len(tStr)        i = InStr(j, tStr, Chr(0))
        
            If i = Len(tStr) Then Exit Sub
                FileNum = FileNum + 1
                FileName(FileNum) = Mid(tStr, j, i - j)
                List1.AddItem FileName(FileNum)
                j = i + 1
            Next i
                        
    End If数组FileName(0)为路径,下标在1以上为文件名
      

  3.   

    Private Sub Command1_Click()
        Dim i As Integer, title As String, FileNames As String
        
        ComDialogFax.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNLongNames
        ComDialogFax.Filter = "All Excel Files (*.xls)|*.xls|All files (*.*)|*.*"
        ComDialogFax.FilterIndex = 1
        ComDialogFax.InitDir = "C:\"
        ComDialogFax.FileName = ""
        ComDialogFax.CancelError = False
        ComDialogFax.ShowOpen
        
        i = InStrRev(ComDialogFax.FileName, "\") '
        title = Left(ComDialogFax.FileName, i) ' Ä¿Â¼
        FileNames = Mid(ComDialogFax.FileName, i + 1) ' all selectes files
        Do While Len(FileNames) > 0
            title = GetLeftWords(FileNames, Chr(0))
            MsgBox title
        Loop
    End SubFunction GetLeftWords(s As String, ByVal Ch As String) As String
        Dim i As Long
        i = InStr(s, Ch)
        If i > 0 Then
            GetLeftWords = Left(s, i - 1)
            s = Mid(s, i + Len(Ch))
        Else
            GetLeftWords = s
            s = vbNullString
        End If
    End Function