Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Open directory dialog API (VB6)

    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

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Open directory dialog API (VB6)

    Mike,
    Try something like:
    <pre>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

    </pre>


    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open directory dialog API (VB6)

    Rory,

    That fit like a glove. Thank you so much.

    Mike

Posting Permissions

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