SaveFileRequester() - How get i the selected Patte

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GPI.

rn (Headline to long :wink:

I want to get the selectet Pattern of a SaveFileRequest(), to find out, in which Format i must save the file.

Or does somebody know the API-function?

GPI

PII 333, 256MB, Asus TNT2Ultra 32MB, AWE Gold 64 4MB
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

Here it is:

Code: Select all

FileData$ = "This is the text to be"+Chr(13)+Chr(10)+"saved in the file."
FileSize = Len(FileData$)
FileData = AllocateMemory(0, FileSize)
PokeS(FileData, FileData$)
CurrentFile$ = "C:\Windows\MyFile.txt"
CurrentFileName$ = GetFilePart(CurrentFile$)
CurrentPath$ = GetPathPart(CurrentFile$)
SavePattern$ = "Plain text (*.txt)|*.txt|HTML Document (*.html;*.htm)|*.html;*.htm"
BufferSize = 512
CurrentFile = AllocateMemory(1, BufferSize)
PokeS(CurrentFile, CurrentFile$)
CurrentFileName = AllocateMemory(2, BufferSize)
PokeS(CurrentFileName, CurrentFileName$)
SavePattern = AllocateMemory(3, BufferSize)
PokeS(SavePattern, SavePattern$)
For i=SavePattern To SavePattern+Len(SavePattern$)  
  If PeekB(i)='|'
    PokeB(i, 0)
  EndIf
Next i
ofn.OPENFILENAME
ofn\lStructSize = SizeOf(OPENFILENAME)
ofn\hwndOwner = 0 ; Use WindowID() when you have an opened window.
ofn\hInstance = GetModuleHandle_(0)
ofn\lpstrFilter = SavePattern
ofn\lpstrCustomFilter = 0
ofn\nMaxCustFilter = 0
ofn\nFilterIndex = 0
ofn\lpstrFile = CurrentFileName
ofn\nMaxFile = BufferSize
ofn\lpstrFileTitle = CurrentFile
ofn\nMaxFileTitle = BufferSize
ofn\lpstrInitialDir = @CurrentPath$
ofn\lpstrTitle = 0
ofn\Flags = #OFN_EXPLORER|#OFN_HIDEREADONLY
ofn\nFileOffset = 0
ofn\nFileExtension = 0
ofn\lpstrDefExt = 0
ofn\lCustData = 0
ofn\lpfnHook = 0
If GetSaveFileName_(ofn)
  File$ = PeekS(CurrentFile)
  FreeMemory(1)
  FreeMemory(2)
  FreeMemory(3)
  position = 1
  For i=1 To ofn\nFilterIndex
    position = FindString(SavePattern$, "|*.", position)+3
    position2 = FindString(SavePattern$, "|", position)
  Next i
  Debug position2-position
  Extension$ = Mid(SavePattern$, position, position2-position)
  If File$
    If OpenFile(0, File$)
      WriteData(FileData, FileSize)
      CloseFile(0)
      FreeMemory(0)
    Else
      MessageRequester("Error", "Unable To save "+File$, 0)
    EndIf
  EndIf
EndIf
End
But I hope Fred adds a SelectedExtension() function, or something like that (it would save a lot of code, as you see).

El_Choni
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GPI.

Thanks, i will try it.

btw: I would it call: SelectedPattern()

PII 333, 256MB, Asus TNT2Ultra 32MB, AWE Gold 64 4MB
Post Reply