Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

BrowseForFolder ( BFF ) Replacement

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Fred Buffington
    replied
    One Note George. I had to put $INCLUDE "WIN32API.INC"
    in the libbff.inc file for it to compile in 6.11. (instead of
    in the bff.bas file)

    ------------------

    Leave a comment:


  • George Bleck
    replied
    Code:
    'This is the include file
    
    '----------------------------------------------------------------------------(')
    
    DECLARE CALLBACK FUNCTION libBFF_dlgMainCallback( )
    DECLARE FUNCTION libBFF_dlgMain( BYVAL hParent AS DWORD, strTitle AS STRING, strMessage AS STRING ) AS STRING
    DECLARE FUNCTION libBFF_GetIconIndex( strFilePath AS STRING ) AS DWORD
    DECLARE FUNCTION libBFF_HasChildren( BYVAL strPath AS STRING ) AS LONG
    DECLARE FUNCTION libBFF_IsParentClosing( BYVAL hItemToCollapse AS DWORD, BYVAL hCheckItem AS DWORD ) AS LONG
    DECLARE FUNCTION libBFF_MakeIcon( ) AS DWORD
    DECLARE FUNCTION libBFF_TVAddSubfilesToNode( BYVAL hITem AS DWORD ) AS LONG
    DECLARE FUNCTION libBFF_TVGetFullPath( BYVAL hItem AS DWORD ) AS STRING
    DECLARE FUNCTION libBFF_TVGetItem( BYVAL hItem AS DWORD ) AS STRING
    DECLARE FUNCTION libBFF_TVInsertItem( BYVAL hParent AS DWORD, strItem AS STRING, BYVAL lngChildrenFlag AS LONG, BYVAL lngIconIndex AS LONG ) AS LONG
    DECLARE SUB libBFF_CloseTheThread( )
    DECLARE SUB libBFF_ExpandNode( BYVAL hItem AS DWORD )
    DECLARE SUB libBFF_OpenTo( BYVAL strPath AS STRING )
    DECLARE SUB libBFF_TVFillRoot( )
    
    '----------------------------------------------------------------------------(')
    
    %SHFILEINFO_DEFINED = %TRUE
    
    '----------------------------------------------------------------------------(')
    
    'Dialog ID Constants
    
    '----------------------------------------------------------------------------(')
    
    %libBFF_ID_btnAccept = 1002
    %libBFF_ID_btnClose = 1003
    %libBFF_ID_dlgMain = 101
    %libBFF_ID_edtSelectedPath = 1005
    %libBFF_ID_staticMessage = 1004
    %libBFF_ID_tvwDirectoryTree = 1001
    
    '----------------------------------------------------------------------------(')
    
    'libBFF_SettingsType.dwdShowType Constants
    
    '----------------------------------------------------------------------------(')
    
    %libBFF_ShowType_DirsOnly = 0
    %libBFF_ShowType_DirsAndFiles = 1
    
    '----------------------------------------------------------------------------(')
    
    'libBFF_SettingsType.dwdDriveTypes Constants
    
    '----------------------------------------------------------------------------(')
    
    %libBFF_DriveType_RootDirectoryDoesNotExist = 2???		'Bad drives
    %libBFF_DriveType_Removable = 4???		'Removeable media only
    %libBFF_DriveType_Fixed = 8???		'Fixed media only (hard drives)
    %libBFF_DriveType_Remote = 16???		'Network drives
    %libBFF_DriveType_RAMDisk = 64???		'RAM drives
    %libBFF_DriveType_CDROM = 32???		'CDROM drives
    %libBFF_DriveType_AllExistingDrives = 124???		'All possible drive types
    
    '----------------------------------------------------------------------------(')
    
    $libBFF_IconPath = "$bffico$.ico"		'Icon (clock) name for the fill thread
    
    '----------------------------------------------------------------------------(')
    
    TYPE libBFF_SettingsType
    	'User selectable options
    	dwdDirAttributeMask AS DWORD		'File attribute mask (read only, hidden, system)
    	dwdDriveTypes AS DWORD		'Fixed, removable, all, etc.
    	dwdFileAttributeMask AS DWORD		'File attribute mask (read only, hidden, system)
    	dwdShowType AS DWORD		'Directories only or Directories and Files
    	strDriveString AS STRING * 26		'Optional list of drive letters, leave blank for all
    	strFileMatchMask AS STRING * 16		'Match to mask file against, ex:  *.bas
    	strBFFPath AS STRING * %MAX_PATH		'Temporary storage of the path returned by BFF
    	'internal use only
    	boolCloseThread AS LONG		'Flag whether to close the fill thread or not
    	hDlg AS DWORD		'BFF main dialog handle
    	hLoadingMessage AS DWORD		'Handle to the loading message item in the treeview
    	hThread AS DWORD		'Handle of the fill thread
    	hThreadItem AS DWORD		'Handle to the item being filled by the fill thread
    	hTreeview AS DWORD		'Handle to the treeview
    END TYPE
    
    '----------------------------------------------------------------------------(')
    
    GLOBAL libBFF_gstructSettings AS libBFF_SettingsType
    
    '----------------------------------------------------------------------------(')
    
    FUNCTION libBFF_dlgMain( BYVAL hParent AS DWORD, strTitle AS STRING, strMessage AS STRING ) AS STRING
    	LOCAL lngResult AS LONG
    	DIALOG NEW hParent, strTitle, 69, 76, 240, 291, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_CENTER OR %DS_3DLOOK OR %DS_NOFAILCREATE _
    	  OR %DS_SETFONT, %WS_EX_WINDOWEDGE OR %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO libBFF_gstructSettings.hDlg
    	CONTROL ADD LABEL, libBFF_gstructSettings.hDlg, %libBFF_ID_staticMessage, strMessage, 9, 6, 222, 21
    	CONTROL ADD "SysTreeView32", libBFF_gstructSettings.hDlg, %libBFF_ID_tvwDirectoryTree, "SysTreeView321", 9, 36, 222, 174, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR %WS_TABSTOP OR %TVS_HASBUTTONS OR %TVS_HASLINES OR %TVS_LINESATROOT OR %TVS_SHOWSELALWAYS, _
    	  %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
    	CONTROL ADD TEXTBOX, libBFF_gstructSettings.hDlg, %libBFF_ID_edtSelectedPath, "", 9, 216, 222, 36, %WS_CHILD OR %WS_VISIBLE OR %ES_LEFT OR %ES_READONLY OR %ES_MULTILINE OR %ES_AUTOVSCROLL OR %WS_VSCROLL, _
    	  %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
    	CONTROL ADD BUTTON, libBFF_gstructSettings.hDlg, %libBFF_ID_btnAccept, "&Accept", 114, 261, 54, 21
    	CONTROL ADD BUTTON, libBFF_gstructSettings.hDlg, %libBFF_ID_btnClose, "&Close", 177, 261, 54, 21
    	DIALOG SHOW MODAL libBFF_gstructSettings.hDlg, CALL libBFF_dlgMainCallback TO lngResult
    	FUNCTION = TRIM$( libBFF_gstructSettings.strBFFPath )
    END FUNCTION
    
    '----------------------------------------------------------------------------(')
    
    SUB libBFF_CloseTheThread( )
    	libBFF_gstructSettings.boolCloseThread = %TRUE
    	DO UNTIL libBFF_gstructSettings.hThread = 0
    		DIALOG DOEVENTS
    	LOOP
    END SUB
    
    '----------------------------------------------------------------------------(')
    
    SUB libBFF_ExpandNode( BYVAL hItem AS DWORD )
    	IF libBFF_gstructSettings.hThread THEN
    		IF TreeView_GetParent( libBFF_gstructSettings.hTreeview, hItem ) = libBFF_gstructSettings.hThreadItem THEN EXIT SUB
    		libBFF_CloseTheThread
    		TreeView_Expand libBFF_gstructSettings.hTreeview, libBFF_gstructSettings.hThreadItem, %TVE_COLLAPSE OR %TVE_COLLAPSERESET
    	END IF
    	'display a "Loading" message as the first child under the node
    	libBFF_gstructSettings.hLoadingMessage = libBFF_TVInsertItem( hItem, "Loading...", 0, libBFF_GetIconIndex( ENVIRON$( "TEMP" ) & $libBFF_IconPath ))
    	'Thread out the fill routine
    	libBFF_gstructSettings.hThreadItem = hItem
    	libBFF_gstructSettings.boolCloseThread = %FALSE
    	THREAD CREATE libBFF_TVAddSubfilesToNode( libBFF_gstructSettings.hThreadItem ) TO libBFF_gstructSettings.hThread
    END SUB
    
    '----------------------------------------------------------------------------(')
    
    CALLBACK FUNCTION libBFF_dlgMainCallback( )
    	LOCAL hSelectedItem AS DWORD
    	LOCAL hSystemImageList AS DWORD
    	LOCAL udtNMTreeview AS NM_TREEVIEW PTR
    	LOCAL udtSHFileInfo AS SHFILEINFO
    	SELECT CASE CBMSG
    		CASE %WM_INITDIALOG
    			INITCOMMONCONTROLS
    			hSystemImageList = SHGETFILEINFO( "C:\", 0, udtSHFileInfo, SIZEOF( udtSHFileInfo ), %SHGFI_USEFILEATTRIBUTES OR %SHGFI_SMALLICON OR %SHGFI_SYSICONINDEX )
    			CONTROL HANDLE CBHNDL, %libBFF_ID_tvwDirectoryTree TO libBFF_gstructSettings.hTreeview
    			TreeView_SetImageList libBFF_gstructSettings.hTreeview, hSystemImageList, %TVSIL_NORMAL
    			libBFF_TVFillRoot
    			libBFF_MakeIcon
    			POSTMESSAGE CBHNDL, %WM_USER + 1, 0, 0
    		CASE %WM_NOTIFY
    			udtNMTreeview = CBLPARAM
    			SELECT CASE @udtNMTreeview.hdr.Code
    				CASE %TVN_ITEMEXPANDING
    					SELECT CASE @udtNMTreeview.action
    						CASE %TVE_EXPAND
    							libBFF_ExpandNode @udtNMTreeview.itemNew.hItem
    						CASE %TVE_COLLAPSE
    							IF libBFF_IsParentClosing( @udtNMTreeview.itemNew.hItem, libBFF_gstructSettings.hThreadItem ) THEN	libBFF_CloseTheThread
    							TreeView_Expand libBFF_gstructSettings.hTreeview, @udtNMTreeview.itemNew.hItem, %TVE_COLLAPSE OR %TVE_COLLAPSERESET
    					END SELECT
    				CASE %TVN_SELCHANGED
    					IF @udtNMTreeview.itemNew.hItem = libBFF_gstructSettings.hLoadingMessage THEN
    						CONTROL SET TEXT libBFF_gstructSettings.hDlg, %libBFF_ID_edtSelectedPath, ""
    					ELSE
    						hSelectedItem = TreeView_GetSelection( libBFF_gstructSettings.hTreeview )
    						CONTROL SET TEXT libBFF_gstructSettings.hDlg, %libBFF_ID_edtSelectedPath, libBFF_TVGetFullPath( hSelectedItem )
    					END IF
    			END SELECT
    		CASE %WM_COMMAND
    			SELECT CASE CBCTL
    				CASE %libBFF_ID_btnAccept
    					IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
    						hSelectedItem = TreeView_GetSelection( libBFF_gstructSettings.hTreeview )
    						IF hSelectedItem THEN
    							libBFF_gstructSettings.strBFFPath = libBFF_TVGetFullPath( hSelectedItem )
    							DIALOG END CBHNDL
    						END IF
    					END IF
    				CASE %libBFF_ID_btnClose
    					IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
    						DIALOG END CBHNDL
    					END IF
    				CASE %WM_DESTROY
    					libBFF_CloseTheThread
    					KILL ENVIRON$( "TEMP" ) & $libBFF_IconPath
    			END SELECT
    		CASE %WM_USER + 1
    			IF libBFF_gstructSettings.strBFFPath <> "" THEN
    				libBff_OpenTo( libBFF_gstructSettings.strBFFPath )
    				libBFF_gstructSettings.strBFFPath = ""
    			END IF
    	END SELECT
    END FUNCTION
    
    '----------------------------------------------------------------------------(')
    
    FUNCTION libBFF_IsParentClosing( BYVAL hItemToCollapse AS DWORD, BYVAL hCheckItem AS DWORD ) AS LONG
    	FUNCTION = %TRUE
    	DO WHILE hCheckItem
    		IF hItemToCollapse = hCheckItem THEN EXIT FUNCTION
    		hCheckItem = TreeView_GetParent( libBFF_gstructSettings.hTreeview, hCheckItem )
    	LOOP
    	FUNCTION = %FALSE
    END FUNCTION
    
    '----------------------------------------------------------------------------(')
    
    FUNCTION libBFF_TVInsertItem( BYVAL hParent AS DWORD, strItem AS STRING, BYVAL lngChildrenFlag AS LONG, BYVAL lngIconIndex AS LONG ) AS LONG
    	LOCAL udtTV_Insertudt AS TV_INSERTSTRUCT
    	udtTV_Insertudt.hParent = hParent
    	udtTV_Insertudt.hInsertAfter = %TVI_LAST
    	udtTV_Insertudt.Item.Item.mask = %TVIF_TEXT OR %TVIF_CHILDREN OR %TVIF_IMAGE OR %TVIF_SELECTEDIMAGE
    	udtTV_Insertudt.Item.Item.pszText = STRPTR( strItem )
    	udtTV_Insertudt.Item.Item.cchTextMax = LEN( strItem )
    	udtTV_Insertudt.Item.Item.cChildren = lngChildrenFlag
    	udtTV_Insertudt.Item.Item.iImage = lngIconIndex
    	udtTV_Insertudt.Item.Item.iSelectedImage = lngIconIndex
    	FUNCTION = TreeView_InsertItem( libBFF_gstructSettings.hTreeview, udtTV_Insertudt )
    END FUNCTION
    
    '----------------------------------------------------------------------------(')
    
    SUB libBFF_TVFillRoot( )
    	LOCAL aszDriveLetter AS ASCIIZ * 4
    	LOCAL lngIndex AS LONG
    	FOR lngIndex = 65 TO 90
    		IF libBFF_gstructSettings.strDriveString <> "" AND INSTR( UCASE$( libBFF_gstructSettings.strDriveString ), CHR$( lngIndex )) = 0 THEN ITERATE
    		aszDriveLetter = CHR$( lngIndex ) & ":\"
    		IF ( 2^ GETDRIVETYPE( aszDriveLetter ) AND libBFF_gstructSettings.dwdDriveTypes ) THEN
    			libBFF_TVInsertItem %TVI_ROOT, LEFT$( aszDriveLetter, 2 ), libBFF_HasChildren( aszDriveLetter ), libBFF_GetIconIndex( BYCOPY aszDriveLetter )
    		END IF
    	NEXT lngIndex
    END SUB
    
    '----------------------------------------------------------------------------(')
    
    FUNCTION libBFF_TVAddSubfilesToNode( BYVAL hITem AS DWORD ) AS LONG
    	LOCAL lngIndex AS LONG
    	LOCAL strArray( ) AS STRING
    	LOCAL strPath AS STRING
    	LOCAL lngResult AS LONG
    	LOCAL hFindFile AS DWORD
    	LOCAL udtWin32FindData AS WIN32_FIND_DATA
    	LOCAL strSearch AS STRING
    	'Get the dirs
    	strPath = libBFF_TVGetFullPath( hItem )
    	hFindFile = FINDFIRSTFILE( BYCOPY strPath & "\*", udtWin32FindData )
    	IF hFindFile <> %INVALID_HANDLE_VALUE THEN
    		DO
    			IF libBFF_gstructSettings.boolCloseThread = %TRUE THEN
    				FINDCLOSE hFindfile
    				GOTO libBFF_TVAddSubfilesToNode_Abend
    			END IF
    			IF ( udtWin32FindData.dwFileAttributes AND %FILE_ATTRIBUTE_DIRECTORY ) = %FILE_ATTRIBUTE_DIRECTORY _
    			  AND udtWin32FindData.cFileName <> "." AND udtWin32FindData.cFileName <> ".." THEN
    				REDIM PRESERVE strArray( UBOUND( strArray ) + 1 )
    				strArray( UBOUND( strArray )) = udtWin32FindData.cFileName
    			END IF
    		LOOP WHILE FINDNEXTFILE( hFindFile, udtWin32FindData )
    		FINDCLOSE hFindFile
    		ARRAY SORT strArray( ), COLLATE UCASE
    	END IF
    	FOR lngIndex = 0 TO UBOUND( strArray )
    		IF libBFF_gstructSettings.boolCloseThread = %TRUE THEN GOTO libBFF_TVAddSubfilesToNode_Abend
    		libBFF_TVInsertItem hItem, _
    		  strArray( lngIndex ), _
    		  libBFF_HasChildren( libBFF_TVGetFullPath( hItem ) & "\" & strArray( lngIndex )), _
    		  libBFF_GetIconIndex( strPath & "\" & strArray( lngIndex ))
    	NEXT lngIndex
    	'get the files
    	IF libBFF_gstructSettings.dwdShowType AND %libBFF_ShowType_DirsAndFiles = %libBFF_ShowType_DirsAndFiles THEN
    		ERASE strArray( )
    		FOR lngIndex = 1 TO PARSECOUNT( libBFF_gstructSettings.strFileMatchMask, "|" )
    			strSearch = strPath & "\" & PARSE$( libBFF_gstructSettings.strFileMatchMask, "|", lngIndex )
    			hFindFile = FINDFIRSTFILE( BYVAL STRPTR( strSearch ), udtWin32FindData )
    			IF hFindFile <> %INVALID_HANDLE_VALUE THEN
    				DO
    					IF libBFF_gstructSettings.boolCloseThread = %TRUE THEN
    						FINDCLOSE hFindfile
    						GOTO libBFF_TVAddSubfilesToNode_Abend
    					END IF
    					IF udtWin32FindData.cFileName <> "." AND udtWin32FindData.cFileName <> ".." _
    					  AND ( udtWin32FindData.dwFileAttributes AND %FILE_ATTRIBUTE_DIRECTORY ) = 0 _
    					  AND ( udtWin32FindData.dwFileAttributes AND libBFF_gstructSettings.dwdFileAttributeMask ) THEN
    						REDIM PRESERVE strArray( UBOUND( strArray ) + 1 )
    						strArray( UBOUND( strArray )) = udtWin32FindData.cFileName
    					END IF
    				LOOP WHILE FINDNEXTFILE( hFindFile, udtWin32FindData )
    				FINDCLOSE hFindFile
    			END IF
    		NEXT lngIndex
    		ARRAY SORT strArray( ), COLLATE UCASE
    		FOR lngIndex = 0 TO UBOUND( strArray )
    			IF libBFF_gstructSettings.boolCloseThread = %TRUE THEN GOTO libBFF_TVAddSubfilesToNode_Abend
    			IF lngIndex = 0 _
    			  OR ( lngIndex > 0 AND strArray( lngIndex - 1 ) <> strArray( lngIndex )) THEN
    				libBFF_TVInsertItem hItem, strArray( lngIndex ), 0, libBFF_GetIconIndex( strPath & "\" & strArray( lngIndex ))
    			END IF
    		NEXT lngIndex
    	END IF
    	'Delete the "loading" message
    	TreeView_DeleteItem libBFF_gstructSettings.hTreeview, TreeView_GetChild( libBFF_gstructSettings.hTreeview, hItem )
    libBFF_TVAddSubfilesToNode_Abend :
    	THREAD CLOSE libBFF_gstructSettings.hThread TO lngResult
    	libBFF_gstructSettings.hThread = 0
    END FUNCTION
    
    '----------------------------------------------------------------------------(')
    
    FUNCTION libBFF_GetIconIndex( strFilePath AS STRING ) AS DWORD
    	LOCAL udtSHFileInfo AS SHFILEINFO
    	SHGETFILEINFO BYVAL STRPTR( strFilePath ), 0, udtSHFileInfo, SIZEOF( udtSHFileInfo ), %SHGFI_SMALLICON OR %SHGFI_SYSICONINDEX
    	FUNCTION = udtSHFileInfo.iIcon
    END FUNCTION
    
    '----------------------------------------------------------------------------(')
    
    FUNCTION libBFF_TVGetItem( BYVAL hItem AS DWORD ) AS STRING
    	LOCAL aszBuffer AS ASCIIZ * %MAX_PATH + 1
    	LOCAL udtTVItem AS TV_ITEM
    	udtTVItem.mask = %TVIF_TEXT OR %TVIF_HANDLE
    	udtTVItem.cchTextMax = SIZEOF( aszBuffer )
    	udtTVItem.pszText = VARPTR( aszBuffer )
    	udtTVItem.hItem = hItem
    	TreeView_GetItem libBFF_gstructSettings.hTreeview, udtTVItem
    	FUNCTION = aszBuffer
    END FUNCTION
    
    '----------------------------------------------------------------------------(')
    
    FUNCTION libBFF_TVGetFullPath( BYVAL hItem AS DWORD ) AS STRING
    	LOCAL strPath AS STRING
    	LOCAL hCurrent AS DWORD
    	hCurrent = hItem
    	DO UNTIL hCurrent = 0
    		strPath = libBFF_TVGetItem( hCurrent ) & "\" & strPath
    		hCurrent = TreeView_GetParent( libBFF_gstructSettings.hTreeview, hCurrent )
    	LOOP
    	FUNCTION = RTRIM$( strPath, "\" )
    END FUNCTION
    
    '----------------------------------------------------------------------------(')
    
    FUNCTION libBFF_MakeIcon( ) AS DWORD
    	LOCAL hFile AS DWORD
    	hFile = FREEFILE
    	OPEN ENVIRON$( "TEMP" ) & $libBFF_IconPath FOR BINARY AS #hFile
    	PUT$ #hFile, PEEK$( CODEPTR( libBFF_MakeIcon_Data ), 318 )
    	CLOSE #hFile
    	EXIT FUNCTION
    libBFF_MakeIcon_Data :
    	!db 000,000,001,000,001,000,016,016,016,000,000,000,000,000,040,001,000,000,022,000,000,000
    	!db 040,000,000,000,016,000,000,000,032,000,000,000,001,000,004,000,000,000,000,000,192,000
    	!db 000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000
    	!db 000,000,128,000,000,128,000,000,000,128,128,000,128,000,000,000,128,000,128,000,128,128
    	!db 000,000,192,192,192,000,128,128,128,000,000,000,255,000,000,255,000,000,000,255,255,000
    	!db 255,000,000,000,255,000,255,000,255,255,000,000,255,255,255,000,255,255,240,000,000,015
    	!db 255,255,255,240,015,247,127,240,015,255,255,015,127,255,255,247,240,255,240,255,255,255
    	!db 255,255,207,015,240,127,255,255,255,252,247,015,015,255,255,255,255,207,255,240,015,255
    	!db 255,255,252,255,255,240,007,255,255,249,207,255,255,112,007,255,255,249,255,255,255,112
    	!db 015,255,255,249,255,255,255,240,015,255,255,249,255,255,255,240,240,127,255,249,255,255
    	!db 247,015,240,255,255,249,255,255,255,015,255,015,127,249,255,247,240,255,255,240,015,247
    	!db 127,240,015,255,255,255,240,000,000,015,255,255,000,000,000,000,000,000,000,000,000,000
    	!db 000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000
    	!db 000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000
    	!db 000,000,000,000,000,000,000,000,000,000
    END FUNCTION
    
    '----------------------------------------------------------------------------(')
    
    FUNCTION libBFF_HasChildren( BYVAL strPath AS STRING ) AS LONG
    	LOCAL hFindFile AS DWORD
    	LOCAL udtWin32FindData AS WIN32_FIND_DATA
    	LOCAL strSearch AS STRING
    	LOCAL lngIndex AS LONG
    	IF RIGHT$( strPath, 1 ) = "\" THEN
    		strSearch = strPath & "*"
    	ELSE
    		strSearch = strPath & "\*"
    	END IF
    	'Check for directories
    	hFindFile = FINDFIRSTFILE( BYVAL STRPTR( strSearch ), udtWin32FindData )
    	IF hFindFile THEN
    		DO
    			IF udtWin32FindData.cFileName <> "." AND udtWin32FindData.cFileName <> ".." THEN		'ignore these
    				IF ( udtWin32FindData.dwFileAttributes AND %FILE_ATTRIBUTE_DIRECTORY ) = %FILE_ATTRIBUTE_DIRECTORY _		'is a dir
    				  AND (( udtWin32FindData.dwFileAttributes AND libBFF_gstructSettings.dwdDirAttributeMask ) OR ( udtWin32FindData.dwFileAttributes = %FILE_ATTRIBUTE_DIRECTORY )) THEN		'matches attributes?
    					FINDCLOSE hFindFile
    					FUNCTION = 1
    					EXIT FUNCTION
    				END IF
    			END IF
    		LOOP WHILE FINDNEXTFILE( hFindFile, udtWin32FindData )
    		FINDCLOSE hFindFile
    	END IF
    	'Check for files
    	IF libBFF_gstructSettings.dwdShowType = %libBFF_ShowType_DirsAndFiles THEN
    		FOR lngIndex = 1 TO PARSECOUNT( libBFF_gstructSettings.strFileMatchMask, "|" )
    			strSearch = strPath & "\" & PARSE$( libBFF_gstructSettings.strFileMatchMask, "|", lngIndex )		'add search mask
    			hFindFile = FINDFIRSTFILE( BYVAL STRPTR( strSearch ), udtWin32FindData )
    			IF hFindFile <> %INVALID_HANDLE_VALUE THEN
    				DO
    					IF udtWin32FindData.cFileName <> "." AND udtWin32FindData.cFileName <> ".." _		'ignore these
    					  AND ( udtWin32FindData.dwFileAttributes AND %FILE_ATTRIBUTE_DIRECTORY ) = 0 _		'is a file
    					  AND (( udtWin32FindData.dwFileAttributes AND libBFF_gstructSettings.dwdFileAttributeMask ) OR ( udtWin32FindData.dwFileAttributes = 0 )) THEN		'matches attributes?
    						FINDCLOSE hFindFile
    						FUNCTION = 1
    						EXIT FUNCTION
    					END IF
    				LOOP WHILE FINDNEXTFILE( hFindFile, udtWin32FindData )
    			END IF
    		NEXT lngIndex
    	END IF
    	FUNCTION = 0
    END FUNCTION
    
    '----------------------------------------------------------------------------(')
    
    SUB libBFF_OpenTo( BYVAL strPath AS STRING )
    	LOCAL lngIndex AS LONG
    	LOCAL strSection AS STRING
    	LOCAL hCurrentHandle AS DWORD
    	hCurrentHandle = %TVI_ROOT
    	FOR lngIndex = 1 TO PARSECOUNT( strPath, "\" )
    		strSection = TRIM$( PARSE$( strPath, "\", lngIndex ))
    		hCurrentHandle = TreeView_GetChild( libBFF_gstructSettings.hTreeview, hCurrentHandle )
    		DO WHILE hCurrentHandle
    			IF UCASE$( libBFF_TVGetItem( hCurrentHandle )) = UCASE$( strSection ) THEN EXIT LOOP
    			hCurrentHandle = TreeView_GetNextSibling( libBFF_gstructSettings.hTreeview, hCurrentHandle )
    		LOOP
    		IF hCurrentHandle = 0 THEN	EXIT SUB		'bad path
    		TreeView_Expand libBFF_gstructSettings.hTreeview, hCurrentHandle, %TVE_EXPAND
    		DO
    			DIALOG DOEVENTS
    		LOOP UNTIL libBFF_gstructSettings.hThread = 0
    		TreeView_Select libBFF_gstructSettings.hTreeview, hCurrentHandle, %TVGN_FIRSTVISIBLE
    		TreeView_Select libBFF_gstructSettings.hTreeview, hCurrentHandle, %TVGN_CARET
    	NEXT lngIndex
    END SUB
    ------------------
    Every day I try to learn one thing new,
    but new things to learn are increasing exponentially.
    At this rate I’m becoming an idiot faster and faster !!!
    ------------------
    George W. Bleck
    Lead Computer Systems Engineer
    KeySpan Corporation



    [This message has been edited by George Bleck (edited April 02, 2003).]

    Leave a comment:


  • George Bleck
    started a topic BrowseForFolder ( BFF ) Replacement

    BrowseForFolder ( BFF ) Replacement

    here is an all code bff replacement with test harness.

    features
    • can browse for directories only or directories and files
    • uses proper icons in the treeview display
    • dyamically builds the directory hierarchy on-the-fly to save time and memory
    • worker thread fills node in the background so you can still interact while it's loading large directories
    • removes collapsed nodes from the treeview to save memory
    • allows masking based on file and directory attributes (read only, hidden, system)
    • allows cut-and-paste of the path without actually saying "ok"
    • fully customizable title and message
    • fully customizable drive type selections
    • fully customizable multiple file match mask (using pipe delimiter)
    • fully customizable everything as you can change the code


    written with
    • pbwin 7.0
    • pbforms 1.0 (metatags removed)
    • winapi32.inc date: 2003-02-19
    • compiles in pbdll 6.11 no problem


    updates
    • 2003-03-17 : (01) corrected glitch that prevented icons from showing on win9x pc's.
    • 2003-03-17 : (02) modified icons section to be more platform/drive generic (by: borje hagsten)
    • 2003-03-19 : (03) plus sign now disappears when an empty directory is selected for expansion (by: david kenny) (removed! see 10)
    • 2003-03-29 : (04) threaded background fill of node with "loading" indicator
    • 2003-03-29 : (05) expanding a node while another is in progress cancels/collapses the in progress expand
    • 2003-03-29 : (06) fixed a handle leak
    • 2003-03-29 : (07) fixed selection of the "loading..." message to return nothing
    • 2003-03-29 : (08) moved some globals around and changed the name of the global udt
    • 2003-03-30 : (09) added pipe seperated search criteria
    • 2003-03-30 : (10) added intelligent folder loading (concept by: borje hagsten)
    • 2003-03-30 : (11) replaced terminatethread with safer code
    • 2003-04-01 : (12) fixed win9x bug with expansion (+/-) symbol not showing
    • 2003-04-01 : (13) add the ability to specify exactly what drive letters to allow to show
    • 2003-04-01 : (14) add the ability to pre-open a specified path
    • 2003-04-02 : (15) fixed some major bugs for file/dirs with no special attributes applied not showing up


    discussion thread

    Code:
    'this is the test harness
    
    '----------------------------------------------------------------------------(')
    
    #compile exe
    #register none
    #include "win32api.inc"
    #include "commctrl.inc"
    #include "libbff.inc"
    
    '----------------------------------------------------------------------------(')
    
    function pbmain( )
    	'must fill in these settings before calling the bff...see constant declarations for options
    	libbff_gstructsettings.dwddirattributemask = %file_attribute_readonly or %file_attribute_hidden or %file_attribute_system	or %file_attribute_normal or %file_attribute_archive	'uses the win32_find_data constants
    	libbff_gstructsettings.dwddrivetypes = %libbff_drivetype_fixed		'which drives types to accept
    	libbff_gstructsettings.dwdfileattributemask = %file_attribute_readonly or %file_attribute_hidden or %file_attribute_system		or %file_attribute_normal or %file_attribute_archive		'uses standard win32_find_data constants
    	libbff_gstructsettings.dwdshowtype = %libbff_showtype_dirsandfiles
    	libbff_gstructsettings.strdrivestring = chr$( 67 to 90 )		'optionally supply the drives letters you wish to allow, leave blank to allow all
    	libbff_gstructsettings.strfilematchmask = "*|*.bas"		'can be a pipe delimted list of masks
    	libbff_gstructsettings.strbffpath = "c:\program files\common files\microsoft shared"		'you can prefill the strbffpath to open that start on that path
    	msgbox "bff returned: " & chr$( 13, 13, 34 ) _
    	  & libbff_dlgmain( %hwnd_desktop, _
    	  "bff replacement title", _
    	  "please select the file or directory you wish to use and click accept," & $cr & "click on the close button to exit without selecting anything" ) & _
    	  $dq
    end function
    ------------------
    every day i try to learn one thing new,
    but new things to learn are increasing exponentially.
    at this rate i’m becoming an idiot faster and faster !!!
    ------------------
    george w. bleck
    lead computer systems engineer
    keyspan corporation



    [this message has been edited by george bleck (edited april 02, 2003).]
Working...
X
😀
🥰
🤢
😎
😡
👍
👎