To MapBasic developers

Last week, Andrew Canfield kindly contributed a MapBasic wrapper for  the
Windows API function BrowseForFolder().

His code gives you the same functionality for directories or folders as the
standard MapBasic function FileOpenDlg() does for individual files.

Documentation for the BrowseForFolder interface can be found  at
www.msdn.microsoft.com by searching for the "SHBrowseForFolder" function

I found that I needed a couple of enhancements to the original code to
1: correctly display a custom prompt above the tree view control in the
dialog box
2: allow the user to browse not just "My Computer" but also "Network
Neighborhood" for a folder to choose

This code works ok for me on W95, W98 and WNT4.

'------------------------------
' bff.mb

Define MAX_PATH 260

Type BrowseInfo
 hWndOwner As Integer
 pIDLRoot As Integer
 pszDisplayName As String
 lpszTitle As String
 ulFlags As Integer
 lpfnCallback As Integer
 lParam As Integer
 iImage As Integer
End Type

Declare Function BrowseForFolder
 (byVal sPrompt As String) As String
Declare Sub CoTaskMemFree Lib "ole32.dll"
 (ByVal hMem As Integer)
Declare Function SHBrowseForFolder Lib "shell32.dll" Alias
"SHBrowseForFolderA"
 (lpbi As BrowseInfo) As Integer
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias
"SHGetPathFromIDListA"
 (ByVal pidList As Integer, lpBuffer As String) As Integer

Declare Sub Main

Sub Main()
 Dim sPrompt As String
 Dim sFolder As String

 sPrompt = "Select a Folder"
 do
  sFolder = BrowseForFolder(sPrompt)
  if sFolder<>"" then
   Note "Selected Folder=["+sFolder+"]"
  end if
 loop until sFolder=""
End Sub

Function BrowseForFolder(byVal sPrompt As String) As String

 Dim lpIDList As Integer
 Dim nResult As Integer
 Dim sPath As String
 Dim bi As BrowseInfo

 sPath = Space$(MAX_PATH)

 bi.hWndOwner = 0
 bi.pidlRoot=0
 bi.pszDisplayName = Space$(MAX_PATH)
 bi.lpszTitle = sPrompt
 bi.ulFlags = 0

 lpIDList = SHBrowseForFolder(bi)
 If lpIDList <> 0 Then
  nResult = SHGetPathFromIDList(lpIDList, sPath)
  Call CoTaskMemFree(lpIDList)
 End If

 BrowseForFolder = RTrim$(sPath)

End Function
'------------------------------

David Haycraft
Information Analysis Associates  Pty Ltd
Email:  [EMAIL PROTECTED]
Web :  www.acslink.aone.net.au/actaa/iaa.htm




---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 3561

Reply via email to