Ooops
September 18, 2021, 06:02:08

Author Topic: a quick file requester question  (Read 280 times)

Offline wadmixfm

  • Full Member
  • ***
  • Posts: 137
a quick file requester question
« on: August 21, 2021, 19:42:09 »
' requestdir.bmx

SuperStrict

local dir$="C:\Blitzmax\Mod\"

Local path:Byte Ptr = RequestDir("Select a Folder",dir)

Print "directory selected was "+path


My question is

How can i tell the file requester to go into the folder ,as it shows the Mod folder but i want the requester to go into that folder so the requester is set so the user can select a folder from the preset folder if you get me.

Lee



Offline Henri

  • Sr. Member
  • ****
  • Posts: 353
Re: a quick file requester question
« Reply #1 on: August 22, 2021, 16:24:02 »
Hi,

it isn't quite clear what you are after.

Providing RequestDir with a default location it selects that location first, but user can select a different folder. Note that default folder needs to exist.

Your path variable should be a String, not Byte Ptr.

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline wadmixfm

  • Full Member
  • ***
  • Posts: 137
Re: a quick file requester question
« Reply #2 on: August 23, 2021, 18:56:03 »
ok when i use string and define the folder path it does go there for example

c:\users\public\my folder\mysub\

in the mysub directory there are other folders

but i want the file selector to go straight to the folder mysub and open that show whats in it

but when i set it it just shows the folder mysub with a > next to it

lee

Offline wadmixfm

  • Full Member
  • ***
  • Posts: 137
Re: a quick file requester question
« Reply #3 on: August 23, 2021, 19:13:24 »
here are 2 pictures

my path is set to C:\Users\Public\Specdrum 3\Bass\

picture called folder 1 - This is the pic when the file selector first shows
picture called folder 2 - after the user scrolls down to the folder called Bass

now i want the file selector to show the contents of the bass folder as in this folder there are at present
4 folders called
CZ Bass
Standard-Bass
1234
Synth-Bass

and in each folder are the samples for each bass set which i can load in when i scroll through but i want the user to click only the folders in the Bass Folder.

is that any clearer ??


Offline wadmixfm

  • Full Member
  • ***
  • Posts: 137
Re: a quick file requester question
« Reply #4 on: August 23, 2021, 19:14:59 »
it works ok on the mac file selector its maybe just windows grrrrr silly microsoft

lee

Offline wadmixfm

  • Full Member
  • ***
  • Posts: 137
Re: a quick file requester question
« Reply #5 on: August 23, 2021, 19:45:21 »
is there another file selector available in the windows version of blitzmax NG , i know it uses windows calls to bring the selector up , so if the user installs a new file selector will blitzmax ng use that new version ??

cheers

lee

Offline Henri

  • Sr. Member
  • ****
  • Posts: 353
Re: a quick file requester question
« Reply #6 on: August 23, 2021, 20:35:00 »
You could try the modern folder/file requester for Windows by col. This is for ng.

See example at the end..

Code: [Select]
SuperStrict
Framework Brl.StandardIO
Import Brl.SystemDefault 'RequestDir()
 
?Win32
 
Import "-lole32"
Import Pub.Win32
 
Global Shell32Dll:Byte Ptr = LoadLibraryA("Shell32.dll")
Global SHCreateItemFromParsingName:Int(pszPath$w,pbc:Byte Ptr,riid:Byte Ptr,ppv:IUnknown_ Var)"Win32" = GetProcAddress(Shell32Dll,"SHCreateItemFromParsingName")
 
Global CLSID_FileOpenDialog:Int[] = [$dc1c5a9c,$4ddee88a,$f860a1a5,$f7ae202a]
Global IID_IFileOpenDialog:Int[] = [$d57c7288,$4768d4ad,$969d02be,$60d93295]
Global IID_IShellItem:Int[] = [$43826d1e,$42eee718,$e2a155bc,$fe7bc361]
 
 
Extern"Win32"
        'These types are INCOMPLETE - DO NOT USE FOR ANYTHING ELSE !!!!!!
        Interface IModalWindow Extends IUnknown_
                Method Show(hWnd:Byte Ptr)
        EndInterface
 
        Interface IFileDialog Extends IModalWindow
                Method SetFileTypes()
                Method SetFileTypeIndex()
                Method GetFileTypeIndex()
                Method Advise()
                Method Unadvise()
                Method SetOptions:Int(dwOptions:Int)
                Method GetOptions:Int(dwOptions:Int Ptr)
                Method SetDefaultFolder:Int(pShellItem:IShellItem)
                Method SetFolder:Int(pSI:IShellItem)
                Method GetFolder()
                Method GetCurrentSelection()
                Method SetFilename:Int(pszName$w)
                Method GetFileName()
                Method SetTitle:Int(pszName$w)
                Method SetOKButtonLabel()
                Method SetFilenameLabel()
                Method GetResult:Int(pItem:IShellItem Var)
                Method AddPlace()
                Method SetDefaultExtension()
                Method Close()
                Method SetClientGuid()
                Method ClearClientData()
                Method SetFilter()
        EndInterface
       
        Interface IFileOpenDialog Extends IFileDialog
                Method GetResults:Int(ppEnum:IShellItemArray Ptr)
                Method GetSelectedItems:Int(ppsai:IShellItemArray Ptr)
        EndInterface
       
        Interface IShellItemArray Extends IUnknown_
                Method BindToHandler()
                Method GetPropertyStore()
                Method GetPropertyDescriptionList()
                Method GetAttributes()
                Method GetCount:Int(pdwNumItems:Int Ptr)
                Method GetItemAt:Int(dwIndex:Int, ppsi:IShellItem Ptr)
                Method EnumItems()
        EndInterface
       
        Interface IShellItem Extends IUnknown_
                Method BindToHandler()
                Method GetParent()
                Method GetDisplayName:Int(sigdnName:Int,ppszName:Short Ptr Var)
                Method GetAttributes()
                Method Compare()
        EndInterface
       
        Function CoCreateInstance:Int(rclsid:Byte Ptr,pUnkOuter:Byte Ptr,dwClsContext:Byte Ptr,riid:Byte Ptr,ppv:IUnknown_ Var)="HRESULT CoCreateInstance(REFCLSID, LPUNKNOWN, DWORD, REFIID, LPVOID)!"
        Function CoInitialize:Int(pvReserved:Byte Ptr)="HRESULT CoInitialize(LPVOID)!"
        Function CoUninitialize()="void CoUninitialize()!"
EndExtern
 
Function RequestFiles:String[](title:String, initialPath:String)
        Global pDialog:IFileOpenDialog
        Global pInitialPath:IShellItem
        Global pResults:IShellItemArray
        Local hr:Byte Ptr
       
        CoInitialize(0)
 
        hr = CoCreateInstance(CLSID_FileOpenDialog,Null,CLSCTX_INPROC_SERVER,IID_IFileOpenDialog,pDialog)
        If hr < 0
Cleanup()
Return [RequestFile(Title,InitialPath)]
        EndIf
       
        Local dwOptions:Int
        pDialog.GetOptions(Varptr dwOptions)
        pDialog.SetOptions(dwOptions|$200) ' $200 = FOS_ALLOWMULTISELECT
 
        'Create an IShellItem for a default folder path
        InitialPath = InitialPath.Replace("/","\")
        If SHCreateItemFromParsingName(InitialPath,Null,IID_IShellItem,pInitialPath) < 0
Cleanup()
Return [RequestFile(Title,InitialPath)]
EndIf

        If pDialog.SetFolder(pInitialPath) < 0
                CleanUp()
                Return [RequestFile(Title,InitialPath)]
        EndIf
 
        ' show it
        pDialog.SetTitle(Title)
        pDialog.Show(0)
 
        ' get the result
        If pDialog.GetResults(Varptr pResults) < 0
                CleanUp()
                Return Null
        EndIf
       
        'Get the results
        Local count:Int
        If pResults.GetCount(Varptr count) < 0
                CleanUp()
                Return Null
        EndIf
 
        Local selectedItemNames:String[count]
        For Local i:Int = 0 Until count
                Local pItem:IShellItem
                If pResults.getItemAt(i, Varptr pItem) >= 0
                        Local pName:Short Ptr
                        pItem.GetDisplayName($80058000,pName)
                        selectedItemNames[i] = String.FromWString(pName)
                EndIf
 
                If pItem pItem.Release_()
        Next
       
        CleanUp()
        Return selectedItemNames
       
        Function CleanUp()
                If pDialog
                        pDialog.Release_()
                        pDialog = Null
                EndIf
                If pInitialPath
                        pInitialPath.Release_()
                        pInitialPath = Null
                EndIf
                If pResults
                        pResults.Release_()
                        pResults = Null
                EndIf
                CoUninitialize()
        EndFunction   
EndFunction
 
 
Function RequestFolder$(Title$,InitialPath$)

        Global pDialog:IFileOpenDialog
        Global pInitialPath:IShellItem
        Global pFolder:IShellItem
        Local hr:Int
        Local ResultFolder$
 
        CoInitialize(0)
 
        'Create Instance of the Dialog
        hr = CoCreateInstance(CLSID_FileOpenDialog,Null,CLSCTX_INPROC_SERVER,IID_IFileOpenDialog,pDialog)
 
        'Not on Vista or Win7?
        If hr < 0
CleanUp()
Return RequestDir(Title,InitialPath)
EndIf
       
        'Set it to Browse Folders
        Local dwOptions:Int
        pDialog.GetOptions(Varptr dwOptions)
        pDialog.SetOptions(dwOptions|$20)
       
        'Set Title
        pDialog.SetTitle(Title)

        'Create an IShellItem for a default folder path
        InitialPath = InitialPath.Replace("/","\")
        hr = SHCreateItemFromParsingName(InitialPath, Null, IID_IShellItem, pInitialPath)
       
        If pDialog.SetFolder(pInitialPath) < 0
                CleanUp()
                Return RequestDir(Title,InitialPath)
        EndIf
               
        'Show the Dialog
        pDialog.Show(0)
 
        'Test the result
        If pDialog.GetResult(pFolder) < 0
                CleanUp
                Return ""
        EndIf
       
        'Get the result
        Local pName:Short Ptr
        pFolder.GetDisplayName($80058000,pName)
        ResultFolder = String.FromWString(pName)
       
        CleanUp()
        Return ResultFolder
       
        Function CleanUp()
                If pDialog
                        pDialog.Release_()
                        pDialog = Null
                EndIf
                If pInitialPath
                        pInitialPath.Release_()
                        pInitialPath = Null
                EndIf
                If pFolder
                        pFolder.Release_()
                        pFolder = Null
                EndIf
                CoUninitialize()
        EndFunction
EndFunction
?
 
'Example Usage
Print RequestFolder("Select a Folder...","")

Local files:String[] = RequestFiles("Select some file(s)","")
For Local file:String = EachIn files
        Print file
Next

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline wadmixfm

  • Full Member
  • ***
  • Posts: 137
Re: a quick file requester question
« Reply #7 on: August 23, 2021, 20:52:57 »
cheers henri

i will give it a try :)

top man

Offline wadmixfm

  • Full Member
  • ***
  • Posts: 137
Re: a quick file requester question
« Reply #8 on: August 23, 2021, 20:56:04 »
Perfect thats what i am after

thank you so much

and to col for creating it

:)

Lee

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal