Results 1 to 5 of 5

Thread: [RESOLVED] Browse Folder

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] Browse Folder

    How to eliminate this \ if I select the hard drive?I have double \\ . How to eliminate this


    Code:
    Private Const BIF_RETURNONLYFSDIRS = &H1
    Private Const BIF_DONTGOBELOWDOMAIN = &H2
    Private Const BIF_STATUSTEXT = &H4
    Private Const BIF_RETURNFSANCESTORS = &H8
    Private Const BIF_EDITBOX = &H10
    Private Const BIF_VALIDATE = &H20
    Private Const BIF_BROWSEFORCOMPUTER = &H1000
    Private Const BIF_BROWSEFORPRINTER = &H2000
    Private Const BIF_BROWSEINCLUDEFILES = &H4000
    
    Private Const MAX_PATH = 260
    
    Private Type T_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
    
    Private Declare Function SHBrowseForFolder Lib "shell32" _
            (lpbi As T_BROWSEINFO) As Long
    
    Private Declare Function SHGetPathFromIDList Lib "shell32" _
            (ByVal pidList As Long, _
            ByVal lpBuffer As String) As Long
    
    Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" _
            (ByVal lpString1 As String, ByVal _
            lpString2 As String) As Long
    
    Public Function BrowseFolder(ByVal HwndOwner As Long, ByRef Titre As String) As String
    
        Dim lpIDList As Long
        Dim sBuffer As String
        Dim BrowseInfo As T_BROWSEINFO
    
        BrowseFolder = ""
        With BrowseInfo
            .HwndOwner = HwndOwner
            .lpszTitle = lstrcat(Titre, "")
            .ulFlags = BIF_RETURNONLYFSDIRS
        End With
    
        lpIDList = SHBrowseForFolder(BrowseInfo)
    
        If (lpIDList) Then
            sBuffer = Space(MAX_PATH)
            SHGetPathFromIDList lpIDList, sBuffer
            sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
            BrowseFolder = sBuffer
        End If
    End Function
    Attached Images Attached Images  

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Browse Folder

    I'm not going to be too much help. Your code works perfectly for me. This is how I used it:
    Code:
    Private Const BIF_RETURNONLYFSDIRS = &H1
    Private Const BIF_DONTGOBELOWDOMAIN = &H2
    Private Const BIF_STATUSTEXT = &H4
    Private Const BIF_RETURNFSANCESTORS = &H8
    Private Const BIF_EDITBOX = &H10
    Private Const BIF_VALIDATE = &H20
    Private Const BIF_BROWSEFORCOMPUTER = &H1000
    Private Const BIF_BROWSEFORPRINTER = &H2000
    Private Const BIF_BROWSEINCLUDEFILES = &H4000
    
    Private Const MAX_PATH = 260
    
    Private Type T_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
    
    Private Declare Function SHBrowseForFolder Lib "shell32" _
            (lpbi As T_BROWSEINFO) As Long
    
    Private Declare Function SHGetPathFromIDList Lib "shell32" _
            (ByVal pidList As Long, _
            ByVal lpBuffer As String) As Long
    
    Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" _
            (ByVal lpString1 As String, ByVal _
            lpString2 As String) As Long
    
    Public Function BrowseFolder(ByVal HwndOwner As Long, ByRef Titre As String) As String
    
        Dim lpIDList As Long
        Dim sBuffer As String
        Dim BrowseInfo As T_BROWSEINFO
    
        BrowseFolder = ""
        With BrowseInfo
            .HwndOwner = HwndOwner
            .lpszTitle = lstrcat(Titre, "")
            .ulFlags = BIF_RETURNONLYFSDIRS
        End With
    
        lpIDList = SHBrowseForFolder(BrowseInfo)
    
        If (lpIDList) Then
            sBuffer = Space(MAX_PATH)
            SHGetPathFromIDList lpIDList, sBuffer
            sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
            BrowseFolder = sBuffer
        End If
    End Function
    
    Private Sub Command1_Click()
    Dim strString As String
    strString = BrowseFolder(Me.hWnd, "A Title")
    Text1.Text = strString
    End Sub
    
    Private Sub Form_Load()
    Text1.Text = ""
    End Sub
    Runing under XP SP2 but that shouldn't make a difference

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Browse Folder

    It works fine for me as well.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Browse Folder

    I have solve this program, the error is I put this in the command button. Text1.Text = strString & "\"

  5. #5
    Addicted Member
    Join Date
    Jul 2007
    Posts
    146

    Re: Browse Folder

    Quote Originally Posted by matrik02
    I have solve this program, the error is I put this in the command button. Text1.Text = strString & "\"
    Perhaps you should think about why you've put it there in the first place and if removing it isn't reintroducing an old problem.
    Jottum™
    XpVistaControls , (transparent) usercontrols for XP, Vista and 7 with W2K legacy support.

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