Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Browse for Folder using API "SHBrowseForFolder"

Posted on 2004-10-04
3
Medium Priority
?
480 Views
Last Modified: 2008-02-01
Hello there ....
I use the following code to browse for a Folder without the CommonDialog Box ...
using the SHBrowseForFolder API ...
But i was thinking is there a way to specify the selected folder upon showing the Browse for folder Dialog Box ??
I mean currently when it starts it selects My computer ...let's say i want it to be pointed to "E:\programs\Audio" by example ....
is this possible ?? it was in the Common DialogBox ...

thank you in Advance
OHDev


'Declaration in Module
Option Explicit

Public 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
Public Const BIF_RETURNONLYFSDIRS = 1
Public Const BIF_STATUSTEXT = 2
Public Const MAX_PATH = 260
Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Public Declare Function lstrcat Lib "Kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long

Public Function BrowseForFolder(HWND As Long, Optional Title As String = "") As String
    Dim iNull As Integer, lpIDList As Long, lResult As Long
    Dim sPath As String, udtBI As BrowseInfo

    With udtBI
        .hwndOwner = HWND
        .lpszTitle = lstrcat(Title, "")
        .ulFlags = BIF_RETURNONLYFSDIRS
    End With

    lpIDList = SHBrowseForFolder(udtBI)
    If lpIDList Then
        sPath = String$(MAX_PATH, 0)
        SHGetPathFromIDList lpIDList, sPath
        CoTaskMemFree lpIDList
        iNull = InStr(sPath, vbNullChar)
        If iNull Then
            sPath = Left$(sPath, iNull - 1)
        End If
    End If

 BrowseForFolder = sPath
End Function


'calling the code:
MsgBox BrowseForFolder(Me.HWND, "Browse for folder")
0
Comment
Question by:OHDev2004
  • 2
3 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 200 total points
ID: 12218934
"This page discusses adding the callback functionality necessary to a [VB6] application in order to to provide the ability to pre-select a folder on the dialog's display."

Pre-selecting a Folder using the Browse Callback

http://vbnet.mvps.org/index.html?code/callback/browsecallback.htm
0
 
LVL 7

Author Comment

by:OHDev2004
ID: 12218977
wow ... thank you Erick very much! ...
OHDev
0
 
LVL 7

Author Comment

by:OHDev2004
ID: 12218995
and sorry for the Low points :( .. LOL
OHDev
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question