VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Create your own multipurpose/Customisable BrowseForFolder.

Ulhas Aswar  (4 Submissions)   Windows API Call/Explanation   VB 6.0   Unknown Difficulty   Mon 3rd November 2003   Mon 8th February 2021

Create your own multipurpose/Customisable BrowseForFolder.

API Declarations


Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" _
(ByVal pIdl As Long, ByVal pszPath As String) As Long
Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
(ByVal hwndOwner As Long, ByVal nFolder As Long, _
pIdl As ITEMIDLIST) As Long
Public Const NOERROR = 0
Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long ' ITEMIDLIST

Type SHITEMID ' mkid
cb As Long ' Size of the ID (including cb itself)
abID() As Byte ' The item ID (variable length)
End Type
Type ITEMIDLIST ' idl
mkid As SHITEMID
End Type

Public Const MAX_PATH = 260

Private Const WM_USER = &H400

Private Const BFFM_INITIALIZED = 1
Private Const BFFM_SELCHANGED = 2

Private Const BFFM_SETSTATUSTEXT = (WM_USER + 100)
Private Const BFFM_SETSELECTION = (WM_USER + 102)

Public m_CurrentDirectory As String


' SHGetSpecialFolderLocation successful rtn val
Public Type BROWSEINFO ' bi

' Handle of the owner window for the dialog box.
hOwner As Long

' Pointer to an item identifier list (an ITEMIDLIST structure) specifying the location
' of the "root" folder to browse from. Only the specified folder and its subfolders
' appear in the dialog box. This member can be NULL, and in that case, the
' name space root (the desktop folder) is used.
pidlRoot As Long

' Pointer to a buffer that receives the display name of the folder selected by the
' user. The size of this buffer is assumed to be MAX_PATH bytes.
pszDisplayName As String

' Pointer to a null-terminated string that is displayed above the tree view control
' in the dialog box. This string can be used to specify instructions to the user.
lpszTitle As String

' Value specifying the types of folders to be listed in the dialog box as well as
' other options. This member can include zero or more of the following values below.
ulFlags As Long

' Address an application-defined function that the dialog box calls when events
' occur. For more information, see the description of the BrowseCallbackProc
' function. This member can be NULL.
lpfn As Long

' Application-defined value that the dialog box passes to the callback function
' (if one is specified).
lParam As Long

' Variable that receives the image associated with the selected folder. The image
' is specified as an index to the system image list.
iImage As Long

End Type
Public Function BrowseCallbackProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal lp As Long, ByVal pData As Long) As Long

Dim lpIDList As Long
Dim ret As Long
Dim sBuffer As String

On Error Resume Next 'Sugested by MS to prevent an error from
'propagating back into the calling process.

Select Case uMsg

Case BFFM_INITIALIZED
Call SendMessage(hwnd, BFFM_SETSELECTION, 1, m_CurrentDirectory)

Case BFFM_SELCHANGED
sBuffer = Space(MAX_PATH)

ret = SHGetPathFromIDList(lp, sBuffer)
If ret = 1 Then
Call SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, sBuffer)
End If

End Select

BrowseCallbackProc = 0

End Function


Rate Create your own multipurpose/Customisable BrowseForFolder. (2(2 Vote))
Create your own multipurpose/Customisable BrowseForFolder..bas

Create your own multipurpose/Customisable BrowseForFolder. Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters