[GELÖST] Requestfile() - Mehrere Dateien?

Übersicht BlitzMax, BlitzMax NG Allgemein

Neue Antwort erstellen

 

CO2

ehemals "SirMO"

Betreff: [GELÖST] Requestfile() - Mehrere Dateien?

BeitragDi, Aug 07, 2012 20:05
Antworten mit Zitat
Benutzer-Profile anzeigen
Hallo,
Kann man Requestfile() so "einstellen", dass man mehrere Dateien auswählen kann? Oder gibt es eine andere Funktion, die das kann?
mfG, CO²

Sprachen: BlitzMax, C, C++, C#, Java
Hardware: Windows 7 Ultimate 64-Bit, AMX FX-6350 (6x3,9 GHz), 32 GB RAM, Nvidia GeForce GTX 750 Ti
  • Zuletzt bearbeitet von CO2 am Do, Aug 09, 2012 14:14, insgesamt einmal bearbeitet

Der Eisvogel

BeitragDo, Aug 09, 2012 13:57
Antworten mit Zitat
Benutzer-Profile anzeigen
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]
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

' prepare filename / path (ripped from BRL's RequestFile())
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
' calculate default index of extension in extension list from path name
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

' allocate cstrings
Local textp:Byte Ptr = text.ToCString()
Local extsp:Byte Ptr = exts.ToCString()
Local dirp:Byte Ptr
If Dir.length > 0 Then dirp = Dir.ToCString()

' prepare file buffer
Local Buf:Byte[MAX_BUFFER_SIZE]
memcpy_( Buf, File, File.length)

' initialize dialog options
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 ' | OFN_LONGNAMES

' display dialog
hwndFocus = GetFocus()
Local n:Int = GetOpenFileName( of)
SetFocus( hwndFocus)

' free cstrings
MemFree textp
MemFree extsp
If dirp Then MemFree dirp

' failure ?
If n <= 0 Then Return Null

' count the number of files
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

' extract filenames into String array
If count = 1 Then
'MARK: im following RequestFile() convention here, and returing "\" path seperators #1
'Return [ String.FromCString( buf).Replace( "\", "/") ]
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
'MARK: im following RequestFile() convention here, and returing "\" path seperators #2
'result[0] = result[0].Replace( "\", "/") + "/"
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
Ungarische Notation kann nützlich sein.
BlitzMax ; Blitz3D
Win 7 Pro 64 Bit ; Intel Core i7-860 ; 8 GB Ram ; ATI HD 5750 1 GB
Projekte: Window-Crasher
Ich liebe es mit der WinAPI zu spielen.
 

CO2

ehemals "SirMO"

BeitragDo, Aug 09, 2012 14:13
Antworten mit Zitat
Benutzer-Profile anzeigen
Ok, vielen Dank!

Funktioniert.
mfG, CO²

Sprachen: BlitzMax, C, C++, C#, Java
Hardware: Windows 7 Ultimate 64-Bit, AMX FX-6350 (6x3,9 GHz), 32 GB RAM, Nvidia GeForce GTX 750 Ti

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group