Results 1 to 4 of 4

Thread: Multi-select files using Open File dialog API..?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300

    Multi-select files using Open File dialog API..?

    I would like to fill a listbox with files using the Open File dialog API. Anyone have code for doing this?

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Nobody has any code using the GetOpenFileName API along with multi-select and then filling a listbox with the selected file names?.....Hmmmmm.

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    Like this:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const OFN_ALLOWMULTISELECT = &H200
    4. Private Const OFN_CREATEPROMPT = &H2000
    5. Private Const OFN_ENABLEHOOK = &H20
    6. Private Const OFN_ENABLETEMPLATE = &H40
    7. Private Const OFN_ENABLETEMPLATEHANDLE = &H80
    8. Private Const OFN_EXPLORER = &H80000                         '  new look commdlg
    9. Private Const OFN_EXTENSIONDIFFERENT = &H400
    10. Private Const OFN_FILEMUSTEXIST = &H1000
    11. Private Const OFN_HIDEREADONLY = &H4
    12. Private Const OFN_LONGNAMES = &H200000                       '  force long names for 3.x modules
    13. Private Const OFN_NOCHANGEDIR = &H8
    14. Private Const OFN_NODEREFERENCELINKS = &H100000
    15. Private Const OFN_NOLONGNAMES = &H40000                      '  force no long names for 4.x modules
    16. Private Const OFN_NONETWORKBUTTON = &H20000
    17. Private Const OFN_NOREADONLYRETURN = &H8000
    18. Private Const OFN_NOTESTFILECREATE = &H10000
    19. Private Const OFN_NOVALIDATE = &H100
    20. Private Const OFN_OVERWRITEPROMPT = &H2
    21. Private Const OFN_PATHMUSTEXIST = &H800
    22. Private Const OFN_READONLY = &H1
    23. Private Const OFN_SHAREAWARE = &H4000
    24. Private Const OFN_SHAREFALLTHROUGH = 2
    25. Private Const OFN_SHARENOWARN = 1
    26. Private Const OFN_SHAREWARN = 0
    27. Private Const OFN_SHOWHELP = &H10
    28.  
    29. Private Type OPENFILENAME
    30.         lStructSize As Long
    31.         hwndOwner As Long
    32.         hInstance As Long
    33.         lpstrFilter As String
    34.         lpstrCustomFilter As String
    35.         nMaxCustFilter As Long
    36.         nFilterIndex As Long
    37.         lpstrFile As String
    38.         nMaxFile As Long
    39.         lpstrFileTitle As String
    40.         nMaxFileTitle As Long
    41.         lpstrInitialDir As String
    42.         lpstrTitle As String
    43.         flags As Long
    44.         nFileOffset As Integer
    45.         nFileExtension As Integer
    46.         lpstrDefExt As String
    47.         lCustData As Long
    48.         lpfnHook As Long
    49.         lpTemplateName As String
    50. End Type
    51.  
    52. Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
    53.  
    54. Private Sub Command1_Click()
    55.     Dim tOPENFILENAME As OPENFILENAME
    56.     Dim lResult As Long
    57.     Dim vFiles As Variant
    58.     Dim lIndex As Long, lStart As Long
    59.    
    60.     With tOPENFILENAME
    61.         .flags = OFN_ALLOWMULTISELECT Or OFN_EXPLORER Or OFN_FILEMUSTEXIST Or OFN_LONGNAMES
    62.         .hwndOwner = hWnd
    63.         .nMaxFile = 2048
    64.         .lpstrFilter = "All Files" & Chr(0) & "*.*" & Chr(0) & Chr(0)
    65.         .lpstrFile = Space(.nMaxFile - 1) & Chr(0)
    66.         .lStructSize = Len(tOPENFILENAME)
    67.     End With
    68.    
    69.     lResult = GetOpenFileName(tOPENFILENAME)
    70.    
    71.     If lResult > 0 Then
    72.         With tOPENFILENAME
    73.             vFiles = Split(Left(.lpstrFile, InStr(.lpstrFile, Chr(0) & Chr(0)) - 1), Chr(0))
    74.         End With
    75.        
    76.         If UBound(vFiles) = 0 Then
    77.             List1.AddItem vFiles(0)
    78.         Else
    79.             For lIndex = 1 To UBound(vFiles)
    80.                 List1.AddItem AddBS(vFiles(0)) & vFiles(lIndex)
    81.             Next
    82.         End If
    83.     End If
    84. End Sub
    85.  
    86. Private Function AddBS(ByVal sPath As String) As String
    87.     If Right$(sPath, 1) <> "\" Then sPath = sPath & "\"
    88.     AddBS = sPath
    89. End Function

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Works great Aaron......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width