• Open directory dialog API (VB6)

    Author
    Topic
    #384255

    I am using that standard API code to display an open file dialog box. I want to modify it so that the user can select a directory only. Can it be done with this or do I need to look at another method? I’m putting the partial code below as a reference:

    With FileDialog
    .DefaultExt = “PDF”
    .DialogTitle = “Select File to Attach”
    .Filter = “Acrobat Files (*.PDF)|*.pdf”
    .InitialDir = OSInfo.MyDocumentsPath ‘SysDefaults.DocRoot ‘
    .FilterIndex = 0
    .Flags = FleFileMustExist + FleHideReadOnly + FleCreatePrompt
    .hWndParent = 0
    .MaxFileSize = 255
    If .Show(True) Then
    sFileName = .FileName
    Else
    lblStatus.Panels(cmMessage).Text = “User Cancelled”

    AttachFile = False
    ‘ lblStatus.Panels(cmMessage).Text = “Ready”

    GoTo Exit_AttachFile:
    End If
    End With

    Viewing 0 reply threads
    Author
    Replies
    • #658483

      Mike,
      Try something like:

      Private Type BrowseInfo
          hWndOwner As Long
          pIDLRoot As Long
          pszDisplayName As Long
          lpszTitle As Long
          ulFlags As Long
          lpfnCallback As Long
          lParam As Long
          iImage As Long
      End Type
      Const BIF_RETURNONLYFSDIRS = 1
      Const MAX_PATH = 260
      Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
      Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" _
         (ByVal lpString1 As String, ByVal lpString2 As String) As Long
      Private Declare Function SHBrowseForFolder Lib "shell32" _
         (lpbi As BrowseInfo) As Long
      Private Declare Function SHGetPathFromIDList Lib "shell32" _
         (ByVal pidList As Long, ByVal lpBuffer As String) As Long
      Public Function ChooseFolder() As String
          Dim iNull As Integer, lpIDList As Long, lResult As Long
          Dim strPath As String, udtBI As BrowseInfo
      
          With udtBI
              .hWndOwner = 0&
              .lpszTitle = lstrcat("Choose folder", "")
              'Return only if the user selected a directory
              .ulFlags = BIF_RETURNONLYFSDIRS
          End With
      
          lpIDList = SHBrowseForFolder(udtBI)
          If lpIDList Then
              strPath = String$(MAX_PATH, 0)
              SHGetPathFromIDList lpIDList, strPath
              'free the block of memory
              CoTaskMemFree lpIDList
              iNull = InStr(strPath, vbNullChar)
              If iNull Then
                  strPath = Left$(strPath, iNull - 1)
              End If
          End If
      
          ChooseFolder = strPath
      End Function
      
      

      Hope that helps.

    Viewing 0 reply threads
    Reply To: Open directory dialog API (VB6)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: