Hallo CO2,
genau das selbe Problem hatte ich vor geraumer Zeit ebenfalls. Hab mich damals auf die Suche nach einer Lösung für Windows gemacht, da ich primär auf Windows arbeite. Folgenden Code habe ich gefunden, und glaube teils etwas geändert:
BlitzMax: [AUSKLAPPEN] [EINKLAPPEN] SuperStrict
Private
Extern "Win32" Function GetOpenFileName:Int( of:Byte Ptr) = "GetOpenFileNameA@4" EndExtern
Const MAX_BUFFER_SIZE:Int = 8192
Const OFN_ALLOWMULTISELECT:Int = 512 Const OFN_CREATEPROMPT:Int = $2000 Const OFN_ENABLEHOOK:Int = 32 Const OFN_ENABLESIZING:Int = $800000 Const OFN_ENABLETEMPLATE:Int = 64 Const OFN_ENABLETEMPLATEHANDLE:Int = 128 Const OFN_EXPLORER:Int = $80000 Const OFN_EXTENSIONDIFFERENT:Int = $400 Const OFN_FILEMUSTEXIST:Int = $1000 Const OFN_HIDEREADONLY:Int = 4 Const OFN_LONGNAMES:Int = $200000 Const OFN_NOCHANGEDIR:Int = 8 Const OFN_NODEREFERENCELINKS:Int = $100000 Const OFN_NOLONGNAMES:Int = $40000 Const OFN_NONETWORKBUTTON:Int = $20000 Const OFN_NOREADONLYRETURN:Int = $8000 Const OFN_NOTESTFILECREATE:Int = $10000 Const OFN_NOVALIDATE:Int = 256 Const OFN_OVERWRITEPROMPT:Int = 2 Const OFN_PATHMUSTEXIST:Int = $800 Const OFN_READONLY:Int = 1 Const OFN_SHAREAWARE:Int = $4000 Const OFN_SHOWHELP:Int = 16 Const OFN_SHAREFALLTHROUGH:Int = 2 Const OFN_SHARENOWARN:Int = 1 Const OFN_SHAREWARN:Int = 0
Type TOpenFileNameA Field lStructSize:Int Field hwndOwner:Int Field hInstance:Int Field lpstrFilter:Byte Ptr Field lpstrCustomFilter:Int Field nMaxCustFilter:Int Field nFilterIndex:Int Field lpstrFile:Byte Ptr Field nMaxFile:Int Field lpstrFileTitle:Byte Ptr Field nMaxFileTitle:Int Field lpstrInitialDir:Byte Ptr Field lpstrTitle:Byte Ptr Field flags:Int Field nFileOffset:Short Field nFileExtension:Short Field lpstrDefExt:Byte Ptr Field lCustData:Int Field lpfnHook:Byte Ptr Field lpTemplateName:Byte Ptr EndType
Public
Function RequestFiles:String[] (text:String, exts:String = Null, path:String = Null) ?MacOs | Linux Local res:String = RequestFile( test, exts, False, path) If res.length <= 0 Then Return Null Return [res] ? ?Win32 Global hwndFocus:Int Local File:String, Dir:String path = path.Replace( "/","\" ) Local i:Int = path.FindLast( "\" ) If i <> -1 Then Dir = path[..i] File = path[i+1..] Else File = path EndIf Local ext:String, defext:Int,p:Int,q:Int p = path.Find(".") If (p>-1) Then ext = "," + path[p+1..].toLower() + "," Local exs:String = exts.toLower() exs = exs.Replace(":",":,") exs = exs.Replace(";",",;") p = exs.find(ext) If p >-1 Then Local q:Int = -1 defext = 1 While True q = exs.find(";",q+1) If q > p Then Exit If q = -1 Then defext = 0 Exit EndIf defext :+ 1 Wend EndIf EndIf If exts Then If exts.Find(":") = -1 Then exts = "Files~0*." + exts Else exts = exts.Replace(":","~0*.") EndIf exts = exts.Replace(";","~0") exts = exts.Replace(",",";*.") + "~0" EndIf Local textp:Byte Ptr = text.ToCString() Local extsp:Byte Ptr = exts.ToCString() Local dirp:Byte Ptr If Dir.length > 0 Then dirp = Dir.ToCString() Local Buf:Byte[MAX_BUFFER_SIZE] memcpy_( Buf, File, File.length) Local of:TOpenFileNameA = New TOpenFileNameA of.lStructSize = SizeOf(TOpenFileNameA) of.hwndOwner = GetActiveWindow() of.lpstrTitle = textp of.lpstrFilter = extsp of.nFilterIndex = defext of.lpstrFile = Buf of.lpstrInitialDir = dirp of.nMaxFile = Buf.length of.flags = OFN_HIDEREADONLY | OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER hwndFocus = GetFocus() Local n:Int = GetOpenFileName( of) SetFocus( hwndFocus) MemFree textp MemFree extsp If dirp Then MemFree dirp
If n <= 0 Then Return Null Local s:Byte Ptr = Buf Local count:Int = 0 While s[0] <> 0 If s[1] = 0 Then count :+ 1 s :+ 2 If s[0] = 0 Then Exit EndIf s :+ 1 Wend If count <= 0 Then Return Null If count = 1 Then Return [ String.FromCString( Buf) ] Else Local result:String[] = New String[count] s = Buf For Local i:Int = 0 Until count result[i] = String.FromCString( s) s :+ result[i].length + 1 If i>0 Then result[i] = result[0]+"\"+result[i] Next result=Result[1..] Return result EndIf EndFunction
Das ganze packst du in eine Datei und bindest es mittels "Import" in dein Programm ein. Dann steht dir die Funktion "RequestFiles" zur Verfügung, die genauso funktioniert, wie das Original, mit dem Unterschied, dass sie dir ein Array mit den Pfaden zu den ausgewählten Dateien zurück liefert.
MfG
Der Eisvogel
|