Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
#Include "win32api.inc"
Function PBMain() As Long
? GetFolder(0, "Select a Folder", "c:\pbwin90")
End Function
Function GetFolder(ByVal hWndModal As Long, szTitle As AsciiZ , szStartFolder As AsciiZ) As String
Local bi As BROWSEINFO, RetPath As String, RetVal, PathID As Long
'settings
bi.hWndOwner = hWndModal
bi.ulFlags = %BIF_ReturnOnlyFSDirs Or %BIF_DontGoBelowDomain Or %BIF_NewDialogStyle
bi.lpfnCallback = CodePtr (BrowseForFolderCallBack) ' to start the search in another place
bi.lparam = VarPtr (szStartFolder)
bi.lpszTitle = VarPtr (szTitle)
'Show the Browse-For-Folder dialog
PathID = SHBrowseForFolder(bi)
If PathID Then
RetPath = Space$(%Max_Path)
RetVal = SHGetPathFromIDList(ByVal PathID, ByVal StrPtr(RetPath))
End If
If RetVal Then
Function = RTrim$(RetPath, Chr$(0))
CoTaskMemFree PathID 'Free allocated memory
End If
End Function
Function BrowseForFolderCallBack (ByVal hwnd As Long,ByVal uMsg As Dword,ByVal wparam As Long, ByVal lparam As Dword) Export As Long
Select Case As uMSG
Case %BFFM_INITIALIZED
If lparam Then SendMessage hWnd, %BFFM_SETSELECTIONA, %TRUE, lparam
End Select
End Function
'gbs_01279
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm