Download text file
#if 0
    ----------------------------                         PowerBASIC v8.x
 ---|          DASoft          |------------------------------------------
    ----------------------------         Code           DATE: 2005-10-01
    | FILE NAME BrowseDIRs.bas |          by
    ----------------------------  Don Schullian, Jr.

              This code is released into the Public Domain
       ----------------------------------------------------------
        No guarantee as to the viability, accuracy, or safety of
         use of this code is implied, warranted, or guaranteed
       ----------------------------------------------------------
                         Use at your own risk!
       ----------------------------------------------------------
                  CONTACT AUTHOR AT don@DASoftVSS.com
 -------------------------------------------------------------------------
   PURPOSE: Quickly select a folder or file
    PARAMS: hParent???  - Parent window or %HWND_DESKTOP
             Flags&     - See list of constants below
             StartPath$ - starting path (if null then whole system start)
             Title$     - 2 line instructions displayed on the dialog
   RETURNS: Selected Path - NULL return on CANCEL
      NOTE: You need to play with the Flags& to get this working the way
            you want. You can also modify the code in the CALLBACK to set
            the dialog's caption.
  -------------------------------------------------------------------------
#endif
'
'-----------------------------------------------------------
'----- Test code -------------------------------------------
'-----------------------------------------------------------
'
#if 1

#COMPILE EXE
#DEBUG ERROR ON
#DIM ALL

%USEMACROS = 1
#INCLUDE "win32api.inc"

DECLARE FUNCTION fBrowseForFolder(OPT BYVAL hParent???,BYVAL Flags&,BYVAL StartPath$,BYVAL Title$) AS STRING

'-------------------------------------
%BIF_RETURNONLYFSDIRS   = &H0001     ' For finding a folder to start document searching
%BIF_DONTGOBELOWDOMAIN  = &H0002     ' For starting the Find Computer
%BIF_STATUSTEXT         = &H0004     ' Top of the dialog has 2 lines of text for BROWSEINFO.lpszTitle and one line if
                                     ' this flag is set.  Passing the message BFFM_SETSTATUSTEXTA to the hwnd can set the
                                     ' rest of the text.  This is not used with BIF_USENEWUI and BROWSEINFO.lpszTitle gets
                                     ' all three lines of text.
%BIF_RETURNFSANCESTORS  = &H0008     '
%BIF_EDITBOX            = &H0010     ' Add an editbox to the dialog
%BIF_VALIDATE           = &H0020     ' insist on valid result (or CANCEL)
%BIF_NEWDIALOGSTYLE     = &H0040     ' Use the new dialog layout with the ability to resize
                                     ' Caller needs to call OleInitialize() before using this API (?)
%BIF_USENEWUI           = &h0050     ' %BIF_NEWDIALOGSTYLE OR %BIF_EDITBOX
%BIF_BROWSEINCLUDEURLS  = &H0080     ' Allow URLs to be displayed or entered. (Requires BIF_USENEWUI)
%BIF_BROWSEFORCOMPUTER  = &H00001000 ' Browsing for Computers.
%BIF_BROWSEFORPRINTER   = &H00002000 ' Browsing for Printers
%BIF_BROWSEINCLUDEFILES = &H00004000 ' Browsing for Everything
%BIF_SHAREABLE          = &H00008000 ' sharable resources displayed (remote shares, requires BIF_USENEWUI)
'-------------------------------------

FUNCTION PBMAIN () AS LONG

  DIM Flags AS LOCAL LONG
  DIM Path  AS LOCAL STRING
  DIM Title AS LOCAL STRING

  Flags = %BIF_STATUSTEXT OR %BIF_NEWDIALOGSTYLE ' Allows new folders to be created & resizing of dialog
  Path  = "c:\temp"
  Title = "This is line 1" & $CR & "This is line 2"

  ? fBrowseForFolder(%HWND_DESKTOP,Flags,Path,Title)

END FUNCTION
#endif
'
'------------------------------------------------------------------------------
'--------- end of test code
'------------------------------------------------------------------------------
'
CALLBACK FUNCTION fBrowseForFolder_CB ()

  DIM zPath AS LOCAL ASCIIz * %MAX_PATH

  SELECT CASE CBMSG
    CASE %BFFM_INITIALIZED : DIALOG SEND CBHNDL, %BFFM_SETSELECTION, %TRUE, CBLPARAM
'                            zPath = "Whatever You Want Here"
'                            SetWindowText CBHNDL, zPath
    CASE %BFFM_SELCHANGED  : SHGetPathFromIDList BYVAL CBWPARAM, zPath
                             IF CBWPARAM = 0 THEN EXIT SELECT
                             SendMessage CBHNDL, %BFFM_SETSTATUSTEXT, %FALSE, BYVAL VARPTR(zPath)
  END SELECT

END FUNCTION
'
'------------------------------------------------------------------------------
'
FUNCTION fBrowseForFolder ( OPT BYVAL hParent    AS DWORD , _
                            OPT BYVAL  Flags     AS LONG  , _
                            OPT BYVAL  StartPath AS STRING, _
                            OPT BYVAL  Title     AS STRING  ) AS STRING

  DIM tBI     AS LOCAL BROWSEINFO
  DIM pIDList AS LOCAL ITEMIDLIST PTR
  DIM zPath   AS LOCAL ASCIIZ * %MAX_PATH


  Title              = Title & $NUL
  zPath              = StartPath
  tBI.hWndOwner      = hParent
  tBI.pidlRoot       = 0                    ' only used if....
  tBI.lpszTitle      = STRPTR(Title)
  tBI.ulFlags        = Flags
  tBI.pszDisplayName = 0 'VARPTR(zDispName) returns the displayed name of the selection eg: "Local Disk (C:)"
  tBI.lParam         = VARPTR(zPath)
  tBI.lpfnCallback   = CODEPTR(fBrowseForFolder_CB)

  pIDList = SHBrowseForFolder(tBI)

  IF pIDList <> 0 THEN
    IF SHGetPathFromIDList(@pIDList, zPath) THEN
      CoTaskMemFree pIDList
      FUNCTION = zPath
    END IF
  END IF

END FUNCTION