Code: Select all
s.s
s="Oops WWWWWWW.lst"
s=OpenFileRequester(s,s,"Image List files (*.lst)|*.lst|Text Files (*.txt)|*.txt|All Files (*.*)|*.*",0)

Code: Select all
s.s
s="Oops WWWWWWW.lst"
s=OpenFileRequester(s,s,"Image List files (*.lst)|*.lst|Text Files (*.txt)|*.txt|All Files (*.*)|*.*",0)
Code: Select all
; skywalk
; Since the built-in PureBasic OFN Requester does not allow Details View!
; Fill the OFN structure and use a OFNHook Procedure.
; Portions modified from Sparkie's code:
; http://www.purebasic.fr/english/viewtopic.php?p=133878#p133878
EnableExplicit
#sNull$ = "-999"
Structure ScanPBDataTypes
  ; These take up no memory and are allowed to grow without redim
  ; when the structure is pointed at a memory buffer.
  ; ex. *buf\d[i] ; 'i' being incremented in a loop
  ; Essentially, this is 1 big StructureUnion.
  b.b[0]  ; byte
  w.w[0]  ; word
  l.l[0]  ; long
  i.i[0]  ; integer
  q.q[0]  ; quad
  f.f[0]  ; float
  d.d[0]  ; double
  a.a[0]  ; ascii
  c.c[0]  ; character
  u.u[0]  ; unicode
  ;s.s{Use 1-MAX String Length expected 255}  ; string
  s.s[0]  ; This supports 1 String scan. *p\s = @x$, *p\s[1] does not work.
EndStructure
Macro FL_FileExists(Fname)
  ;  0 = File or Folder does not exist
  ;  1 = File Exists
  ; -1 = Folder Exists
  ; Since FileSize() returns:
  ;       -1 = File Not found.
  ;       -2 = File is a directory.
  ;        0 = Empty File, > 1 = File Exists
  ;        FileSize() respects '*' wildcards and reports results accordingly.
  FileSize(Fname) + 1
EndMacro
Procedure.i SF_CharReplace(*p.ScanPBDataTypes, StrFrom$="|", StrTo$=#NULL$)
  ; REV:  111227, skywalk
  ; SYNTAX:   nNulls = SF_CharReplace(@x$,"|",#Null$,0)
  ; DEFAULT:  Edit a string in memory to embed null char's = Chr(0)
  ; RETURN:   # of char replacements made.
  ; If StrFrom$=#Null$, then buffer end is assumed to be double null position.
  ; Accepts multiple chars, but only works with the 1st char.
  ; Works with unicode or ascii.
  Protected.i i, msLen, nChars
  Protected.i CharFrom = Asc(StrFrom$)
  Protected.i CharTo = Asc(StrTo$)
  ; Determine msLen
  If CharFrom = #Null   ; Search memory for double nulls = end of string buffer
    While msLen < 64000
      If *p\c[msLen] = 0 And *p\c[msLen+1] = 0
        Break
      EndIf
      msLen + 1
    Wend
    msLen - 1  ; Ignore the final #Null later in code
  Else
    msLen = MemoryStringLength(*p) - 1  ; Get Len in characters, not bytes.
   ; StringByteLength(PeekS(*p))        ; Returns nBytes and depends on ascii/unicode switch!
  EndIf
  For i = 0 To msLen   ; Since walking through String by Character, no need to count bytes/char.
    If *p\c[i] = CharFrom
      *p\c[i] = CharTo
      nChars + 1
    EndIf
  Next i
  ;ShowMemoryViewer(@*p,msLen+32)
  ProcedureReturn nChars
EndProcedure
;-{ GUI FILE STUFF
#OSVEX_LENGTH           = 88  ; If > Win2K = 88 Else = 76
#CDN_INITDONE           = #CDN_FIRST - 0
#CDN_SELCHANGE          = #CDN_FIRST - 1
#CDN_FOLDERCHANGE       = #CDN_FIRST - 2
#OFN_VIEW_REPORT        = $702C
#OFN_VIEW_LIST          = $702B
#OFN_VIEW_LARGEICON     = $7029
#OFN_VIEW_SMALLICON     = $702A
#OFN_VIEW_THUMBNAIL     = $702D
#OFN_VIEW_THUMBNAIL_2K  = $7031
#OFN_VIEW_TILE          = $702E
#OFN_ENABLESIZING       = $800000
#OFS_FILE_OPEN_FLAGS    = #OFN_EXPLORER | #OFN_LONGNAMES | #OFN_CREATEPROMPT
#OFS_FILE_SAVE_FLAGS    = #OFN_EXPLORER | #OFN_LONGNAMES | #OFN_OVERWRITEPROMPT | #OFN_HIDEREADONLY
Structure OFNdata
  Title$
  DefFilePath$
  Pattern$
  PatternPos.i
  MultiSelect.i
  Array Files$(0)
  nFiles.i
EndStructure
Structure OFNgui Extends OFNdata  ; Used by OFN Dialog gui
  guiX.i
  guiY.i
  guiWd.i
  guiHt.i
EndStructure
Global OFNreq.OFNgui, OFNres.OFNdata
; Custom message for move/resize OpenFileRequester
Global gui_OFN_MoveDlg = RegisterWindowMessage_(@"gui_OFN_MoveDlg")
Procedure gui_OFN_HookProc(hW, msg, wP, lP)
  Protected.i hParent, hLV, ri
  Select msg
  Case #WM_INITDIALOG
    ;                                 wd,           ht
    PostMessage_(hW, gui_OFN_MoveDlg, OFNreq\guiWd, OFNreq\guiHt)
  Case gui_OFN_MoveDlg
    ; Reposition @ resize dialog window
    hParent = GetParent_(hW)
    MoveWindow_(hParent, OFNreq\guiX, OFNreq\guiY, wP, lP, 1)
  Case #WM_NOTIFY
    ; hW is the handle to the dialog
    ; hParent is the handle to the common control
    ; hLV is the handle to the listview itself
    hParent = GetParent_(hW)
    hLV = FindWindowEx_(hParent, 0, "SHELLDLL_DefView", #NULL$)
    If hLV
      ri = SendMessage_(hLV, #WM_COMMAND, #OFN_VIEW_REPORT, #Null)
    EndIf
  EndSelect
  ProcedureReturn 0
EndProcedure
Procedure.i gui_FileRequester(hW.i, *pReq.OFNgui, *pRes.OFNdata)
  ; REV:  120106, skywalk
  ; Process user response to OpenFileRequester File Selection(s)
  ; Results go in structure OFNres
  ; If MultiSelect=1,  then OFNres\File$(nFiles-1) contains the list of files
  ;               =0,  then OFNres\File$(0)        contains the 1 selected file
  ; SYNTAX: nFiles = gui_FileRequester(hW, @myOFNreq, @myOFNres)
  Protected.i i, j, *selectedFile, bufferSize
  Protected.s folder$, nextFile$
  ; For Filter to function properly, replace "|" with null Chr(0) directly in memory
  ; Filter must end with 2 null chars
  If Right(*pReq\Pattern$,2) <> "||"
    *pReq\Pattern$ + "||"
  EndIf
  SF_CharReplace(@*pReq\Pattern$)
  If *pReq\MultiSelect
    bufferSize = 32000
  Else
    bufferSize = 512
  EndIf
  ; Buffer to hold selected file name(s)
  *selectedFile = AllocateMemory(bufferSize)
  If Len(GetFilePart(*pReq\DefFilePath$))
    PokeS(*selectedFile,*pReq\DefFilePath$)
  Else
    PokeB(*selectedFile, 0)   ; 1st byte must be null if no initial file name is to be displayed
  EndIf
  ;ShowMemoryViewer(*selectedFile,750)
  Protected myOFN.OPENFILENAME
  myOFN\hwndOwner         = hW
  myOFN\lStructSize       = SizeOf(OPENFILENAME) + 12 ; #OSVEX_LENGTH = 88
  myOFN\hInstance         = #Null
  myOFN\lpstrFilter       = @*pReq\Pattern$
  myOFN\lpstrCustomFilter = #Null
  myOFN\nMaxCustFilter    = #Null
  myOFN\nFilterIndex      = *pReq\patternPos
  myOFN\lpstrFile         = *selectedFile
  myOFN\nMaxFile          = bufferSize
  myOFN\lpstrFileTitle    = #Null
  myOFN\nMaxFileTitle     = #Null
  myOFN\lpstrInitialDir   = @*pReq\DefFilePath$
  myOFN\lpstrTitle        = @*pReq\Title$
  myOFN\flags             = #OFS_FILE_OPEN_FLAGS | #OFN_ENABLESIZING  ;| #OFN_NOCHANGEDIR
  myOFN\lpfnHook          = @gui_OFN_HookProc()
  If *pReq\multiSelect
    myOFN\flags | #OFN_ALLOWMULTISELECT
  EndIf
  GetOpenFileName_(@myOFN)
  
  FreeMemory(*selectedFile)
  ProcedureReturn *pRes\nFiles
EndProcedure
;-}
Enumeration
  #gadResults
  #gadBrowseFiles
  #gadBrowsePaths
  #gadClear
EndEnumeration
Define.i i,evG
Define.s s$
If #PB_Compiler_Unicode
  s$ = "Get Files w/Details View in Unicode"
Else
  s$ = "Get Files w/Details View in Ascii"
EndIf
If OpenWindow(0,0,0,440,340,s$,#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  EditorGadget(#gadResults,20,40,400,300)
  ButtonGadget(#gadBrowseFiles,20,0,100,20,"Browse For File(s)...")
  ButtonGadget(#gadBrowsePaths,130,0,100,20,"Browse For Path(s)...")
  ButtonGadget(#gadClear,390,0,30,20,"Clear")
  Repeat
    Select WaitWindowEvent(5)
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      evG = EventGadget()
      Select evG
      Case #gadClear
        ClearGadgetItems(#gadResults)
      Case #gadBrowseFiles
        OFNreq\guiX         = 20
        OFNreq\guiY         = 20
        OFNreq\guiWd        = 300
        OFNreq\guiHt        = 300
        OFNreq\Title$       = "Select File(s)"
        OFNreq\DefFilePath$ = "Oops WWWWWWW.lst"
        OFNreq\MultiSelect  = 1
        OFNreq\PatternPos   = 1
        OFNreq\Pattern$     = "Image List files (*.lst)|*.lst|Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
        If gui_FileRequester(WindowID(0), @OFNreq, @OFNres)
          AddGadgetItem(#gadResults,-1, Str(OFNres\nFiles) + " File(s) From '" + OFNres\DefFilePath$ + "' =")
          For i = 0  To OFNres\nFiles - 1
            AddGadgetItem(#gadResults,#PB_Any,OFNres\Files$(i))
          Next i
        EndIf
      EndSelect
    EndSelect
  ForEver
EndIfCode: Select all
Procedure Test(n$)
  OpenFileRequester("Test",n$,"Image List files (*.lst)|*.lst|Text Files (*.txt)|*.txt|All Files (*.*)|*.*",0)
EndProcedure
Test("1234567890.lst") ; Shows all.
Test("123456789012.lst") ; Cropped.
Code: Select all
Procedure LongName(Parameter)
  Delay(300)
  keybd_event_(#VK_CONTROL,0,0,0)
  keybd_event_(#VK_C,0,0,0) 
  keybd_event_(#VK_C,0,#KEYEVENTF_KEYUP,0)
  keybd_event_(#VK_V,0,0,0) 
  keybd_event_(#VK_V,0,#KEYEVENTF_KEYUP,0)  
  keybd_event_(#VK_CONTROL,0,#KEYEVENTF_KEYUP,0)
EndProcedure
Thread = CreateThread(@LongName(), 0)
File$ = OpenFileRequester("Please choose file to load", "Oops WWWWWWW.lst", "", 0)
If File$ <> ""
   Debug File$
EndIf
If IsThread(Thread)
   KillThread(Thread)
EndIf
Code: Select all
Global Hook,Run
Procedure HookCB( uMsg , wParam , lParam)   
   Select uMsg
     Case #HC_ACTION
          Run + 1
          hwnd = FindWindow_(0,"Please choose file to load")
          If hWnd And Run = 1
              keybd_event_(#VK_HOME,0,0,0)
              keybd_event_(#VK_HOME,0,#KEYEVENTF_KEYUP,0)
              keybd_event_(#VK_CONTROL,0,0,0)
              keybd_event_(#VK_A,0,0,0)
              keybd_event_(#VK_A,0,#KEYEVENTF_KEYUP,0)
              keybd_event_(#VK_CONTROL,0,#KEYEVENTF_KEYUP,0)
          EndIf
        
   EndSelect   
   ProcedureReturn Result
EndProcedure
Hook = SetWindowsHookEx_(#WH_FOREGROUNDIDLE, @HookCB() , 0, GetCurrentThreadId_())
Pattern$ = "Text (*.txt)|*.txt;*.bat|PureBasic (*.pb)|*.pb|All files (*.*)|*.*"
Pattern = 0 
File$ = OpenFileRequester("Please choose file to load","Oops WWWWWWW.lst", Pattern$, Pattern)
Debug File$
UnhookWindowsHookEx_(Hook)

Code: Select all
If hWnd And Run = 4
Code: Select all
Global Result.s  
  
#OSVEX_LENGTH           = 88 
#CDN_INITDONE           = #CDN_FIRST - 0
#CDN_SELCHANGE          = #CDN_FIRST - 1
#CDN_FOLDERCHANGE       = #CDN_FIRST - 2
#OFN_VIEW_REPORT        = $702C
#OFN_VIEW_LIST          = $702B
#OFN_VIEW_LARGEICON     = $7029
#OFN_VIEW_SMALLICON     = $702A
#OFN_VIEW_THUMBNAIL     = $702D
#OFN_VIEW_THUMBNAIL_2K  = $7031
#OFN_VIEW_TILE          = $702E
#OFN_ENABLESIZING       = $800000
#OFS_FILE_OPEN_FLAGS    = #OFN_EXPLORER | #OFN_LONGNAMES | #OFN_CREATEPROMPT
#OFS_FILE_SAVE_FLAGS    = #OFN_EXPLORER | #OFN_LONGNAMES | #OFN_OVERWRITEPROMPT | #OFN_HIDEREADONLY 
#CDN_FIRST = (-601) 
#CDN_SELCHANGE = (#CDN_FIRST - 1) 
Structure OPENFILENAMEXP Extends OPENFILENAME
  pvReserved.l
  dwReserved.l
  FlagsEx.i
EndStructure   
  
Procedure.s My_OpenFileRequester(Title$,Pattern$,Defdir$,Deffile$)
    Pattern$ = Pattern$ + "|"
    Dim x(10):n=1
     For i = 1 To Len(Pattern$)
      If PeekB(@Pattern$+i) = 124
         x(n) = i
         n+1
      EndIf
     Next
     
     For k=1 To n-1
        PokeB(@Pattern$+x(k),0)
     Next
          
    of.OPENFILENAMEXP
    of\lStructSize = SizeOf(of) 
    of\lpstrTitle = @Title$
    of\lpstrInitialDir = @Defdir$
    of\lpstrFilter = @Pattern$
    of\nMaxFile = #MAX_PATH 
    of\lpstrFile = @Deffile$
    ;of\lpfnHook = @OFHookProc()
    of\lCustData = OpenYesNo
    of\Flags     = #OFS_FILE_OPEN_FLAGS | #OFN_ENABLEHOOK| #OFN_ENABLESIZING  ;#OFS_FILE_OPEN_FLAGS | #OFN_ENABLESIZING Flags for new style
    of\FlagsEx   = 0
    If GetOpenFileName_(of) 
      Result = PeekS(of\lpstrFile)
    EndIf
    ProcedureReturn Result 
EndProcedure   
  
Title$   = "Please choose file to load"
Pattern$ = "Text (*.txt)|*.txt;*.bat|PureBasic (*.pb)|*.pb|All files (*.*)|*.*"
Defdir$  = "E:\"
Deffile$ = "Oops WWWWWWW.lst"
My_OpenFileRequester(Title$,Pattern$,Defdir$,Deffile$)
Debug Result
Code: Select all
of\Flags     = #OFS_FILE_OPEN_FLAGS |  #OFN_ENABLESIZING 

RASHAD wrote:Hi LJ
Yes I know but I am too lazy these days![]()
Code: Select all
Procedure.i SendKey (key.a, up.i)
   Protected send.Input
   
   send\type = #INPUT_KEYBOARD
   send\ki\wVk = key
   If up = #False
      send\ki\dwFlags = 0
   Else
      send\ki\dwFlags = #KEYEVENTF_KEYUP
   EndIf
   
   ProcedureReturn SendInput_(1, @send, SizeOf(Input))
EndProcedure
Macro SendKeyDown (_key_)
   SendKey(_key_, #False)
EndMacro
Macro SendKeyUp (_key_)
   SendKey(_key_, #True)
EndMacro
;-------------------------------------------------------------
Procedure KeyInput (Parameter)
   Delay(400)
   SendKeyDown(#VK_HOME)
   SendKeyUp  (#VK_HOME)
EndProcedure
Thread = CreateThread(@KeyInput(), 0)
File$ = OpenFileRequester("Please choose file to load", "Oops WWWWWWW.lst", "", 0)
If File$ <> ""
   Debug File$
EndIf
If IsThread(Thread)
   KillThread(Thread)
EndIf