Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 109,297 VB Programmers for FREE! Ask your question and get quick answers from experts. There are 1,209 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Browse Folder Dialog

 
Reply to this topicStart new topic

Browse Folder Dialog, Initial browsing directory

Zhalix
post 3 Jul, 2008 - 09:47 PM
Post #1


D.I.C Head

**
Joined: 7 May, 2008
Posts: 217



Thanked 9 times
My Contributions


I'm just wondering if it's possible using my current method to give the Browse Folder Dialog an initial browsing directory, meaning when it opens, it's already browsed to the appropriate folder.

I'm using the following API to create the dialog box:
CODE

Option Explicit

Private Type BrowseInfo
    lngHwnd        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 Const BIF_RETURNONLYFSDIRS = 1
Private 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 BrowseForFolder(ByVal lngHwnd As Long, ByVal strPrompt As String) As String

    On Error GoTo ehBrowseForFolder 'Trap for errors

    Dim intNull As Integer
    Dim lngIDList As Long, lngResult As Long
    Dim strPath As String
    Dim udtBI As BrowseInfo

    'Set API properties (housed in a UDT)
    With udtBI
        .lngHwnd = lngHwnd
        .lpszTitle = lstrcat(strPrompt, "")
        .ulFlags = BIF_RETURNONLYFSDIRS
    End With

    'Display the browse folder...
    lngIDList = SHBrowseForFolder(udtBI)

    If lngIDList <> 0 Then
        'Create string of nulls so it will fill in with the path
        strPath = String(MAX_PATH, 0)

        'Retrieves the path selected, places in the null
         'character filled string
        lngResult = SHGetPathFromIDList(lngIDList, strPath)

        'Frees memory
        Call CoTaskMemFree(lngIDList)

        'Find the first instance of a null character,
         'so we can get just the path
        intNull = InStr(strPath, vbNullChar)
        'Greater than 0 means the path exists...
        If intNull > 0 Then
            'Set the value
            strPath = Left(strPath, intNull - 1)
        End If
    End If

    'Return the path name
    BrowseForFolder = strPath
    Exit Function 'Abort

ehBrowseForFolder:

    'Return no value
    BrowseForFolder = Empty

End Function


I would like this feature because in the program I'm developing, there are many subdirectories within a particular folder, and I would like to browse to these subdirectories quickly. If the dialog is already browsed to the main folder, I can simply click one of the subdirectories and it would be much faster. It is rather annoying to start at the very beginning every time it opens.

I looked into the DirListBox control but I couldn't find a way to accomplish this in it either. Plus I dislike the way it looks and feels, so I hope I don't have to resort to that.

If it's not possible with my current method, then any suggestions for alternatives would be appreciated.
User is offlineProfile CardPM

Go to the top of the page


Zhalix
post 5 Jul, 2008 - 12:28 AM
Post #2


D.I.C Head

**
Joined: 7 May, 2008
Posts: 217



Thanked 9 times
My Contributions


Again, if I wasn't clear enough: an alternative would be acceptable. I just want a visual way to browse through my folders that supports the option of having a starting directory.
User is offlineProfile CardPM

Go to the top of the page

Ken Halter
post 11 Jul, 2008 - 08:34 PM
Post #3


New D.I.C Head

*
Joined: 18 Nov, 2007
Posts: 35



Thanked 4 times
My Contributions


Well... there'll be code changes (of course), but yep. You can pre-select a folder.

http://vbnet.mvps.org/code/callback/browsecallback.htm

If you look at the articles in the "Related" section there, you'll find you can do quite a lot with that dialog.
User is offlineProfile CardPM

Go to the top of the page

Zhalix
post 11 Jul, 2008 - 11:19 PM
Post #4


D.I.C Head

**
Joined: 7 May, 2008
Posts: 217



Thanked 9 times
My Contributions


Thank you! I haven't clicked the link yet so I don't know what I'll find, but I was losing hope that I would receive help on this particular issue.
User is offlineProfile CardPM

Go to the top of the page

Ken Halter
post 12 Jul, 2008 - 09:13 AM
Post #5


New D.I.C Head

*
Joined: 18 Nov, 2007
Posts: 35



Thanked 4 times
My Contributions


Glad to help... that site's awesome. That's why it has over 75,000,000 hits :-)

He was ticked off in a bad way when he found that MS named their new version of VB VBnet. I believe they tried to buy his domain name, too.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 9/6/08 09:42AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month