Seite 1 von 1

PathRequesterEx (windows only)

Verfasst: 23.04.2010 19:58
von ts-soft
Ich hoffe mal, der Code existiert hier noch nicht :D (hab es jedenfalls nicht gefunden)

Code: Alles auswählen

; PathRequesterEx
; Windows Only
; PB 4.40 and above
; Author: Thomas <ts-soft> Schulz
; CoAuthor: Stephen <srod> Rodriguez
; Version 1.1, 24.04.2010
;
; The first and second parameter the same as in PB
;
; you can use a CSIDL-Constant (optional), InitialPath will be ignored!
; CSIDL-Constants see: http://msdn.microsoft.com/de-de/library/bb979138.aspx
;
; for Flags see http://msdn.microsoft.com/en-us/library/bb773205%28VS.85%29.aspx
;
; No directory can be chosen above the initial directory!

EnableExplicit

Procedure.s PathRequesterEx(Title.s, InitialPath.s = "", CSIDL = #PB_Default, Flags = 0)
  Protected.ITEMIDLIST *ppidl
  Protected.BROWSEINFO Dir
  Protected result
  Protected.s folder = Space(#MAX_PATH)
  Protected *Path, t1$

  CoInitialize_(#Null)

  If CSIDL = #PB_Default
    *Path =  AllocateMemory(StringByteLength(InitialPath, #PB_Unicode) + 2)
    PokeS(*Path, InitialPath, -1, #PB_Unicode)
    *ppidl = ILCreateFromPath_(*Path)
    FreeMemory(*Path)
  Else
    SHGetSpecialFolderLocation_(GetActiveWindow_(), CSIDL, @*ppidl)
  EndIf

  With Dir
    \hwndOwner = GetActiveWindow_()
    \pidlRoot = *ppidl
    \pszDisplayName = @folder
    \lpszTitle = @Title
    \ulFlags = Flags
  EndWith

  result = SHBrowseForFolder_(@dir)
  If result And Dir\pszDisplayName
    t1$ = Folder
    SHGetPathFromIDList_(result, @Folder)
    If Folder = ""
      Folder = t1$
    EndIf
    CoTaskMemFree_(result)
  EndIf
  CoTaskMemFree_(*ppidl)
  CoUninitialize_()

  If Folder
    If FileSize(Folder) = -2
      If Right(Folder, 1) <> "\" : Folder + "\" : EndIf
    EndIf
  EndIf

  ProcedureReturn Folder
EndProcedure

; Example:
Debug PathRequesterEx("Select savedir:", "", #CSIDL_PERSONAL)
Debug PathRequesterEx("Select PureBasic Source:",  #PB_Compiler_Home +  "Examples\Sources\",  #PB_Default, #BIF_BROWSEINCLUDEFILES) 
Debug PathRequesterEx("Select Printer:", "", #CSIDL_PRINTERS, #BIF_BROWSEFORPRINTER | #BIF_NEWDIALOGSTYLE | #BIF_NONEWFOLDERBUTTON)

Falls jemand Fehler findet, bitte melden!

Hab mit ASCII, Unicode, x86 und x64 getestet.

Gruß

Thomas

Re: PathRequesterEx (windows only)

Verfasst: 23.04.2010 20:06
von Andesdaf
interessant, bei mir funktioniert alles :allright:

Re: PathRequesterEx (windows only)

Verfasst: 23.04.2010 20:36
von RSBasic
Cool, ein sehr schöner Code, sehr interessant für meine WinAPI Library :mrgreen:
Danke fürs Teilen :allright:

Re: PathRequesterEx (windows only)

Verfasst: 23.04.2010 22:53
von ts-soft
Schon wieder 2 glücklich gemacht :wink:

Code klein wenig angepaßt, damit auch Dateien korrekt zurückgegeben werden.
Beispiel:

Code: Alles auswählen

Debug PathRequesterEx("Wähle PureBasic Source:", #PB_Compiler_Home + "Examples\Sources\", #PB_Default, #BIF_BROWSEINCLUDEFILES)

Re: PathRequesterEx (windows only)

Verfasst: 24.04.2010 13:44
von ts-soft
Update:
Jetzt funktionierts auch mit Druckern!
Danke an srod :D

Re: PathRequesterEx (windows only)

Verfasst: 24.04.2010 18:55
von al90
Schöne Erweiterung. Wird man bestimmt noch gut gebrauchen können. :allright: