I have so much to learn!
Thx for those pointers. I have streamlined my code as much as possible
This is about as simple As I can get it I think.
I use the function return to detect a CANCEL by the user
and I pass the selected folder back using the Initial path variable.
I like this cos I can write on line of code to call the function
and check the result for a cancel:
IF FolderDialog(0,"Select a folder", Path) THEN
So here is what I got:
Code:
#COMPILE EXE "FindFldr.exe" #INCLUDE "WIN32API.INC" ' Win API definitions '************************************************************************ ' Find Folder Declarations '************************************************************************ TYPE browseinfo hwndowner AS LONG pidlroot AS LONG pszdisplayname AS ASCIIZ PTR lpsztitle AS ASCIIZ PTR ulflags AS LONG lpfncallback AS LONG lparam AS LONG iimage AS LONG END TYPE %BFFM_SETSELECTION = %wm_user+102 ' must be this value (102) DECLARE SUB CoTaskMemFree LIB "ole32.dll" ALIAS "CoTaskMemFree" (BYVAL hMem AS LONG) '************************************************************************ ' Find Folder '************************************************************************ CALLBACK FUNCTION fbrowseproc DIM zdir AS ASCIIZ*%max_path IF CBMSG = 1 THEN DIALOG SEND CBHNDL, %BFFM_SETSELECTION, %TRUE, CBLPARAM ' %BFFM_INITIALIZED IF CBMSG = 2 THEN CALL SHGETPATHFROMIDLIST(BYVAL CBWPARAM, zDir) ' %BFFM_SELCHANGED END FUNCTION FUNCTION FolderDialog(hwnd AS LONG, title AS STRING, Dir AS ASCIIZ*%max_path ) AS LONG LOCAL zbuffer AS ASCIIZ*%max_path LOCAL lpidlist AS LONG LOCAL zstartdir AS ASCIIZ*%max_path LOCAL tbi AS browseinfo tbi.hwndowner = hwnd tbi.lpsztitle = STRPTR(title) zstartdir = Dir tbi.ulflags = &h0001 OR &h0002 OR &h0004 tbi.pidlroot = 0 tbi.lpfncallback = CODEPTR(fbrowseproc) ' Select Starting folder tbi.lparam = VARPTR(zstartdir) lpidlist = SHBROWSEFORFOLDER(tbi) IF lpidlist THEN CALL SHGETPATHFROMIDLIST (lpidlist&, Dir) ' Return the path CALL CoTaskMemFree(lpidlist&) FUNCTION = 1 ' User choose a Folder (0 if he hits Cancel) END IF END FUNCTION '************************************************************************ FUNCTION PBMAIN()AS LONG LOCAL Path AS ASCIIZ*%max_path Path = "C:\PBDLL60\BIN" ' Starting Directory IF FolderDialog(0,"Select a folder", Path) THEN MSGBOX Path END IF END FUNCTION '************************************************************************
------------------
Kind Regards
Mike
[This message has been edited by Mike Trader (edited July 06, 2001).]
Leave a comment: