Date: 02-16-2022
Return to Index
'Compilable Example: (Jose Includes)
created by gbSnippets
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#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 lp As Long, ByVal pData As Dword) Export As Long
Local hNode As Dword, szClassName As WStringZ * %Max_Path
Select Case As uMSG
Case %BFFM_INITIALIZED
If pData Then SendMessage hWnd, %BFFM_SETSELECTIONA, %TRUE, pData
Case %BFFM_SELCHANGED
EnumChildWindows(hWnd,CodePtr(ParentCallback),0)
End Select
End Function
Function ParentCallback (ByVal hWndChild As Long, lParam As Long) As Long
Dim szClass As WStringZ * %Max_Path, lRes As Long, hNode As Dword
lRes = GetClassName(hWndChild, szClass, SizeOf(szClass))
If szClass = "SysTreeView32" Then
hNode = TreeView_GetSelection(hWndChild)
TreeView_EnsureVisible hWndChild, hNode
End If
Function = 1
End Function
'gbs_01278
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm