Solved

Browse for Folder using API "SHBrowseForFolder"

Posted on 2004-10-04
3
387 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 50 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now