Multiple File selections...

BlitzPlus Forums/BlitzPlus Programming/Multiple File selections...

BarcodeGeek(Posted 2003) [#1]
Hey.
Im currently trying to code an MP3 player for myself in B+.
I'm planing on using playlists with the applcation, and Im having some issues.

I intend to have a menu option that links to a window that allows the user to select MP3's from a directory, and add them to a new list. I figure that using RequestFile function linked to an 'Add' button, but it doesn't seem to allow you to pick more than one file at a time..(you cant shift click selections) One at a time could take a while if you want to add 50 trakcs from one dir..

I am doing somthing stupid? Or does anyone know of a way round this problem??
Thanks,
BG


CS_TBL(Posted 2003) [#2]
If B+ has no standard solution for this, then it seems you need to code your own filemenu with that feature ..

Otherwise you could load a whole dir (RequestDir), open all mp3 files in it (just the 'filenames' not the content itself), create a listbox-sorta-thing where you select your tunes, and load them. Since the standard listbox doesn't have multiselect, I guess you've to make your own listbox with this feature then.. tho it can't be as hard as making your own filerequester .. :)

otherwise .. I dunno~


BarcodeGeek(Posted 2003) [#3]
Good idea; that was what I was thinking I may have to do - I think the way I will do it somthing like;
open a dir, full of mp3s, which creates the LB,
then wait for a mouse click event within the area of the LB.
Use GetSelectedItem(?) to add the song cliked on to the second LB - which contains the users songs to add to the list.
Or somthing like that..


But WhyTF doesnt the B+ requestFile function allow multiple selection? Seems a bit of a shame...


Tazzy(Posted 2003) [#4]
Or you could write a wrapper around GetOpenFilename from the common dialogs. Below is some Microsoft documentation
about the GetOpenFile function

[a]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/commondialogboxlibrary/commondialogboxreference/commondialogboxfunctions/getopenfilename.asp[/a]

I can't check my documentation from here, but if requestfile
has a flags parameter, then the VB code below might have some usefull info for you.

Const OFN_ALLOWMULTISELECT As Long = &H200
Const OFN_CREATEPROMPT As Long = &H2000
Const OFN_DONTADDTORECENT As Long = &H2000000
Const OFN_ENABLEHOOK As Long = &H20
Const OFN_ENABLEINCLUDENOTIFY As Long = &H400000
Const OFN_ENABLESIZING As Long = &H800000
Const OFN_ENABLETEMPLATE As Long = &H40
Const OFN_ENABLETEMPLATEHANDLE As Long = &H80
Const OFN_EX_NOPLACESBAR As Long = &H1
Const OFN_EXPLORER As Long = &H80000
Const OFN_EXTENSIONDIFFERENT As Long = &H400
Const OFN_FILEMUSTEXIST As Long = &H1000
Const OFN_FORCESHOWHIDDEN As Long = &H10000000
Const OFN_HIDEREADONLY As Long = &H4
Const OFN_LONGNAMES As Long = &H200000
Const OFN_NOCHANGEDIR As Long = &H8
Const OFN_NODEREFERENCELINKS As Long = &H100000
Const OFN_NOLONGNAMES As Long = &H40000
Const OFN_NONETWORKBUTTON As Long = &H20000
Const OFN_NOREADONLYRETURN As Long = &H8000
Const OFN_NOTESTFILECREATE As Long = &H10000
Const OFN_NOVALIDATE As Long = &H100
Const OFN_OVERWRITEPROMPT As Long = &H2
Const OFN_PATHMUSTEXIST As Long = &H800
Const OFN_READONLY As Long = &H1
Const OFN_SHAREAWARE As Long = &H4000
Const OFN_SHAREFALLTHROUGH As Long = 2
Const OFN_SHARENOWARN As Long = 1
Const OFN_SHAREWARN As Long = 0
Const OFN_SHOWHELP As Long = &H10
Const OFN_USEMONIKERS As Long = &H1000000
Const OFS_MAXPATHNAME As Long = 128

Good luck,

tazzy


Tazzy(Posted 2003) [#5]
Oops... found documentation now. No flags parameter :(

Then at least I can give you this VB sourcecode that does the trick. No time to convert it to Blitz. Sorry

The code below returns a string to the buffer lpstrFileTitle with multiple names seperated by ';' Offcourse the buffer needs to be big enough to fit those names in.

Good luck,

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type

Private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@...
    Dim OFName As OPENFILENAME
    OFName.lStructSize = Len(OFName)
    OFName.hwndOwner = 0
    OFName.hInstance = 0
    'Select a filter
    OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
    'create a buffer for the file
    OFName.lpstrFile = Space$(254)
    'set the maximum length of a returned file
    OFName.nMaxFile = 255
    'Create a buffer for the file title
    OFName.lpstrFileTitle = Space$(254)
    'Set the maximum length of a returned file title
    OFName.nMaxFileTitle = 255
    'Set the initial directory
    OFName.lpstrInitialDir = "C:\"
    'Set the title
    OFName.lpstrTitle = "Open File - KPD-Team 1998"
    'No flags
    OFName.flags = 512 ;OFN_ALLOWMULTISELECT

    'Show the 'Open File'-dialog
    If GetOpenFileName(OFName) Then
        MsgBox "File to Open: " + Trim$(OFName.lpstrFile)
    Else
        MsgBox "Cancel was pressed"
    End If
End Sub



Tazzy(Posted 2003) [#6]
Hi Guys,

Had a shot at converting to Blitz, but strings and buffer don't work as I expected. Anyone who can fix this ? I tries shorts instead of bytes because of the unicode, but as soon as I put a pointer to a bank in a bank, it seems to crash. Also CallDll works better that a userlib. Any ideas ?

This is what I created so far...
[code]

Const OFN_ALLOWMULTISELECT = $200
Const OFN_CREATEPROMPT = $2000
Const OFN_DONTADDTORECENT = $2000000
Const OFN_ENABLEHOOK = $20
Const OFN_ENABLEINCLUDENOTIFY = $400000
Const OFN_ENABLESIZING = $800000
Const OFN_ENABLETEMPLATE = $40
Const OFN_ENABLETEMPLATEHANDLE = $80
Const OFN_EX_NOPLACESBAR = $1
Const OFN_EXPLORER = $80000
Const OFN_EXTENSIONDIFFERENT = $400
Const OFN_FILEMUSTEXIST = $1000
Const OFN_FORCESHOWHIDDEN = $10000000
Const OFN_HIDEREADONLY = $4
Const OFN_LONGNAMES = $200000
Const OFN_NOCHANGEDIR = $8
Const OFN_NODEREFERENCELINKS = $100000
Const OFN_NOLONGNAMES = $40000
Const OFN_NONETWORKBUTTON = $20000
Const OFN_NOREADONLYRETURN = $8000
Const OFN_NOTESTFILECREATE = $10000
Const OFN_NOVALIDATE = $100
Const OFN_OVERWRITEPROMPT = $2
Const OFN_PATHMUSTEXIST = $800
Const OFN_READONLY = $1
Const OFN_SHAREAWARE = $4000
Const OFN_SHAREFALLTHROUGH = 2
Const OFN_SHARENOWARN = 1
Const OFN_SHAREWARN = 0
Const OFN_SHOWHELP = $10
Const OFN_USEMONIKERS = $1000000
Const OFS_MAXPATHNAME = 128


DebugLog(SelectFiles("Please select file","Blitz Basic (*.bb);*.bb;","C:\",OFN_EXPLORER + OFN_ALLOWMULTISELECT))

Function SelectFiles$(psTitle$,psFilter$,psInitialDir$,flags)

sFiles$ = ""

bnkTitle = CreateStringBuffer(psTitle$)
bnkFilter = CreateStringBuffer(psFilter,True)
bnkInitDir = CreateStringBuffer(psInitialDir$)

bnkFile = CreateBank(2048)
bnkFileTitle = CreateBank(2048)

bnkInfo = CreateBank(76)
PokeInt bnkInfo, 0,76 ;lStructSize
PokeInt bnkInfo, 4,0 ;hwndOwner
PokeInt bnkInfo, 8,0 ;hInstance
PokeInt bnkInfo,12,0 ;bnkFilter ;lpstrFilter
PokeInt bnkInfo,16,0 ;lpstrCustomFilter
PokeInt bnkInfo,20,0 ;nMaxCustFilter
PokeInt bnkInfo,24,0 ;nFilterIndex
PokeInt bnkInfo,28,bnkFile ;lpstrFile
PokeInt bnkInfo,32,2047 ;nMaxFile
PokeInt bnkInfo,36,0;bnkFileTitle ;lpstrFileTitle
PokeInt bnkInfo,40,2047 ;nMaxFileTitle
PokeInt bnkInfo,44,0;bnkInitDir ;lpstrInitialDir
PokeInt bnkInfo,48,0 ;bnkTitle ;lpstrTitle
PokeInt bnkInfo,52,flags ;flags
PokeShort bnkInfo,56,0 ;nFileOffset
PokeShort bnkInfo,58,0 ;nFileExtension
PokeInt bnkInfo,60,0 ;lpstrDefExt
PokeInt bnkInfo,64,0 ;lCustData
PokeInt bnkInfo,68,0 ;lpfnHook
PokeInt bnkInfo,72,0 ;lpTemplateName

iRC = CallDLL("comdlg32.dll","GetOpenFileNameA",bnkInfo)

If iRC Then
sFiles$ = PeekString(bnkFile)
EndIf

FreeBank bnkFile
FreeBank bnkFileTitle
FreeBank bnkTitle
FreeBank bnkFilter
FreeBank bnkInitDir

FreeBank bnkInfo

If iRC Then
Return sFiles$
Else
Return "Cancelled"
EndIf


End Function

Function CreateStringBuffer(psBuffer$,piConvertZero =False)
iLen = Len(psBuffer$)
bnkX = CreateBank(iLen + 2)
intChar = 0
For i = 0 To iLen
intChar = Asc(Mid(psBuffer,i,1))
If intChar = 59 Then ;';'
If piConvertZero Then
intChar = 0
EndIf
EndIf
;UniCode
PokeByte(bnkX,i,intChar)
Next
;Closing zero
PokeByte(bnkX,i,0)
Return bnkX
End Function

Function PeekString$(pbnkBuffer,piConvertZero=False)

sBuffer$ = ""
For i = 0 To BankSize(pbnkBuffer)
iByte = PeekByte(pbnkBuffer,i)
sBuffer = sBuffer + Chr(iByte)
Next
Return sBuffer
End Function
[/code/


Tazzy(Posted 2003) [#7]
again. Now with formatting :(

Const OFN_ALLOWMULTISELECT  = $200 
Const OFN_CREATEPROMPT  = $2000 
Const OFN_DONTADDTORECENT  = $2000000 
Const OFN_ENABLEHOOK  = $20 
Const OFN_ENABLEINCLUDENOTIFY  = $400000 
Const OFN_ENABLESIZING  = $800000 
Const OFN_ENABLETEMPLATE  = $40 
Const OFN_ENABLETEMPLATEHANDLE  = $80 
Const OFN_EX_NOPLACESBAR  = $1 
Const OFN_EXPLORER  = $80000 
Const OFN_EXTENSIONDIFFERENT  = $400 
Const OFN_FILEMUSTEXIST  = $1000 
Const OFN_FORCESHOWHIDDEN  = $10000000 
Const OFN_HIDEREADONLY  = $4 
Const OFN_LONGNAMES  = $200000 
Const OFN_NOCHANGEDIR  = $8 
Const OFN_NODEREFERENCELINKS  = $100000 
Const OFN_NOLONGNAMES  = $40000 
Const OFN_NONETWORKBUTTON  = $20000 
Const OFN_NOREADONLYRETURN  = $8000 
Const OFN_NOTESTFILECREATE  = $10000 
Const OFN_NOVALIDATE  = $100 
Const OFN_OVERWRITEPROMPT  = $2 
Const OFN_PATHMUSTEXIST  = $800 
Const OFN_READONLY  = $1 
Const OFN_SHAREAWARE  = $4000 
Const OFN_SHAREFALLTHROUGH  = 2 
Const OFN_SHARENOWARN  = 1 
Const OFN_SHAREWARN  = 0 
Const OFN_SHOWHELP  = $10 
Const OFN_USEMONIKERS  = $1000000 
Const OFS_MAXPATHNAME  = 128 


DebugLog(SelectFiles("Please select file","Blitz Basic (*.bb);*.bb;","C:\",OFN_EXPLORER + OFN_ALLOWMULTISELECT))

Function SelectFiles$(psTitle$,psFilter$,psInitialDir$,flags)
	
	sFiles$ = ""
	
    bnkTitle = CreateStringBuffer(psTitle$)
	bnkFilter = CreateStringBuffer(psFilter,True)
	bnkInitDir = CreateStringBuffer(psInitialDir$)
	
	bnkFile = CreateBank(2048)
	bnkFileTitle = CreateBank(2048)
	
	bnkInfo = CreateBank(76)
	PokeInt   bnkInfo, 0,76            ;lStructSize
	PokeInt   bnkInfo, 4,0             ;hwndOwner
	PokeInt   bnkInfo, 8,0             ;hInstance
	PokeInt   bnkInfo,12,0 ;bnkFilter     ;lpstrFilter
	PokeInt   bnkInfo,16,0             ;lpstrCustomFilter
	PokeInt   bnkInfo,20,0             ;nMaxCustFilter
	PokeInt   bnkInfo,24,0             ;nFilterIndex
	PokeInt   bnkInfo,28,bnkFile       ;lpstrFile
	PokeInt   bnkInfo,32,2047          ;nMaxFile
	PokeInt   bnkInfo,36,0;bnkFileTitle  ;lpstrFileTitle
	PokeInt   bnkInfo,40,2047          ;nMaxFileTitle
	PokeInt   bnkInfo,44,0;bnkInitDir    ;lpstrInitialDir
	PokeInt   bnkInfo,48,0 ;bnkTitle      ;lpstrTitle
	PokeInt   bnkInfo,52,flags         ;flags
	PokeShort bnkInfo,56,0             ;nFileOffset
	PokeShort bnkInfo,58,0             ;nFileExtension
	PokeInt   bnkInfo,60,0             ;lpstrDefExt
	PokeInt   bnkInfo,64,0             ;lCustData
	PokeInt   bnkInfo,68,0             ;lpfnHook
	PokeInt   bnkInfo,72,0             ;lpTemplateName
	
	iRC = CallDLL("comdlg32.dll","GetOpenFileNameA",bnkInfo)
	
	If iRC Then
       sFiles$ = PeekString(bnkFile)
	EndIf
	
	FreeBank bnkFile
	FreeBank bnkFileTitle
	FreeBank bnkTitle
	FreeBank bnkFilter
	FreeBank bnkInitDir
	
	FreeBank bnkInfo
	
	If iRC Then
		Return sFiles$
	Else
		Return "Cancelled"
	EndIf
	
	
End Function

Function CreateStringBuffer(psBuffer$,piConvertZero =False)
	iLen = Len(psBuffer$) 
	bnkX = CreateBank(iLen + 2)
	intChar = 0
	For i = 0 To iLen 
		intChar = Asc(Mid(psBuffer,i,1))
		If intChar = 59 Then ;';'
			If piConvertZero  Then
				intChar = 0
			EndIf
		EndIf
		;UniCode
		PokeByte(bnkX,i,intChar)
	Next
	;Closing zero
	PokeByte(bnkX,i,0)
	Return bnkX
End Function

Function PeekString$(pbnkBuffer,piConvertZero=False)
	
	sBuffer$ = ""
	For i = 0 To BankSize(pbnkBuffer)
		iByte = PeekByte(pbnkBuffer,i)
		sBuffer = sBuffer + Chr(iByte)
	Next
	Return sBuffer
End Function