SaveRequester() + Getting the selected Pattern

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

SaveRequester() + Getting the selected Pattern

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by GPI.

Code: Select all

;Thanks to El_Choni for help.
Global SaveRequester_Position
Procedure.s SaveRequester(Title$,File$,Pattern$,Position,flags, WindowID = #Null)
  
  path$=GetPathPart(file$)
  
  BufferSize = 512
  
  memblock$=Space(buffersize*3)
  CurrentFile = @memblock$
  PokeS(CurrentFile,file$)
  
  CurrentFileName = @memblock$+buffersize
  PokeS(CurrentFileName,GetFilePart(file$))
  
  pattern$+"||"
  SavePattern = @memblock$+buffersize+buffersize
  PokeS(SavePattern, Pattern$)
  
  For i=SavePattern To SavePattern+Len(Pattern$)
    If PeekB(i)='|'
      PokeB(i, 0)
    EndIf
  Next i
  
  ofn.OPENFILENAME
  ofn\lStructSize = SizeOf(OPENFILENAME)
  ofn\hwndOwner = WindowID ; returns 0, if no window
  ofn\hInstance = GetModuleHandle_(0)
  ofn\lpstrFilter = SavePattern
  ofn\lpstrCustomFilter = 0
  ofn\nMaxCustFilter = 0
  ofn\nFilterIndex = position-1
  ofn\lpstrFile = CurrentFileName
  ofn\nMaxFile = BufferSize
  ofn\lpstrFileTitle = CurrentFile
  ofn\nMaxFileTitle = BufferSize
  ofn\lpstrInitialDir = @path$
  If title$
    ofn\lpstrtitle = @title$
  Else
    ofn\lpstrTitle = 0
  EndIf
  ofn\Flags = #OFN_EXPLORER | flags
  ofn\nFileOffset = 0
  ofn\nFileExtension = 0
  ofn\lpstrDefExt = 0
  ofn\lCustData = 0
  ofn\lpfnHook = 0
  
  If GetSaveFileName_(ofn)
    File$ = PeekS(CurrentFile)
    SaveRequester_Position=ofn\nFilterIndex-1
    ProcedureReturn file$
  Else
    ProcedureReturn ""       
  EndIf
EndProcedure

Debug SaveRequester("","Hallo.exe","Plain text (*.txt)|*.txt|HTML Document (*.html;*.htm)|*.html;*.htm",1,0)
Debug SaveRequester_position

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