Browse for Folder - How?

Windows specific questions.
Post Reply
Macq
Posts: 24
Joined: Feb 18, 2021 4:01
Location: Queensland, Australia

Browse for Folder - How?

Post by Macq »

I want something like openFileDialog but I want it to return a path that I can then use as a default location for future operations.

I found this:
https://learn.microsoft.com/en-us/windo ... eforfolder
which calls Shell32.dll but how do I do that, and is there an easier way?
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Browse for Folder - How?

Post by Josep Roca »

Use the WIndows API function SHBrowseForFolder
https://learn.microsoft.com/en-us/windo ... forfoldera
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Browse for Folder - How?

Post by srvaldez »

hello Macq
maybe this will be of help viewtopic.php?p=262364&hilit=open+dialog#p262364
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Browse for Folder - How?

Post by dodicat »

Simple browser to navigate to a folder.

Code: Select all

#include "windows.bi"
#include "win\shlobj.bi"

Function folderbrowser (Byref title As String = "Choose A Folder") As String
    Dim bi As BROWSEINFO
    Dim pidl As LPITEMIDLIST
    Dim physpath As Zstring * MAX_PATH
    Dim dispname As Zstring * MAX_PATH
    bi.hwndOwner = HWND_DESKTOP
    bi.pszDisplayName = @dispname
    bi.lpszTitle = Strptr(title)
    bi.ulFlags = 0
    bi.lpfn = null
    bi.lParam = 0
    bi.iImage = 0
    pidl = SHBrowseForFolder(@bi)
    If pidl <> 0 Then
        If SHGetPathFromIDList(pidl, physpath) = 0 Then
            Function = ""
        Else
            Function = physpath
        End If
        CoTaskMemFree pidl
    Else
        Function = ""
    End If
End Function

print folderbrowser

sleep

  
Macq
Posts: 24
Joined: Feb 18, 2021 4:01
Location: Queensland, Australia

Re: Browse for Folder - How?

Post by Macq »

Thanks for all the help, and a special thanks to dodicat for that sweet little example. :D
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Browse for Folder - How?

Post by D.J.Peters »

Code: Select all

#include "win\shlobj.bi"

function BrowseForFolder(byval pszTitle As const zstring ptr = @"Choose A Folder") As String
  static as Zstring * MAX_PATH path
  Dim As BROWSEINFO bi
  bi.hwndOwner = HWND_DESKTOP
  bi.lpszTitle = pszTitle
  bi.ulFlags   = BIF_USENEWUI 
  var pidl     = SHBrowseForFolder(@bi)
  If pidl      = NULL then return ""
  var bResult  = SHGetPathFromIDList(pidl, path)
  CoTaskMemFree(pidl)
  return iif(bResult,path,"")
end function

print BrowseForFolder("what's up babe :-) resize, reorder or drag and drop !")
sleep
Post Reply