Author Topic: BrowseForFolder Default Folder?  (Read 10873 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
BrowseForFolder Default Folder?
« on: January 16, 2010, 08:44:33 PM »
When using the BrowseForFolder method of the Shell.Application Object, is there any way to specify a "default" folder?

I realise that you can specify a root folder, above which the user cannot select, but can you specify a folder that will appear when the method is invoked?

Lee

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: BrowseForFolder Default Folder?
« Reply #1 on: January 16, 2010, 11:26:58 PM »
Specifying the Root folder does open the dilaog at that location. The user can then select any folder in that folder's tree, they just can't go above it.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: BrowseForFolder Default Folder?
« Reply #2 on: January 17, 2010, 07:54:43 AM »
Specifying the Root folder does open the dilaog at that location. The user can then select any folder in that folder's tree, they just can't go above it.

Thanks Jeff,

I realised it was capable of that - but I wondered if it was possible to open at a location, without having the limitation of a root folder.. but perhaps it is not possible  :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: BrowseForFolder Default Folder?
« Reply #4 on: January 17, 2010, 04:17:52 PM »
Thanks Alan for your time  :-)

That last link to "Experts Exchange" seems to be exactly my question, but it seems that you have to sign up to their site to get the solution...  :-(

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: BrowseForFolder Default Folder?
« Reply #5 on: January 17, 2010, 05:03:10 PM »
Yea, that stopped me!
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Chuck Gabriel

  • Guest
Re: BrowseForFolder Default Folder?
« Reply #6 on: January 17, 2010, 06:44:02 PM »
I seem to recall that if you scroll all the way to the bottom of their pages, you can see the actual answers.

Chuck Gabriel

  • Guest
Re: BrowseForFolder Default Folder?
« Reply #7 on: January 17, 2010, 07:14:59 PM »
Oh.  Sorry.  I guess that doesn't work any more.  I would have checked it myself, but I can't see links in threads on theswamp when I'm browsing from my Blackberry.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: BrowseForFolder Default Folder?
« Reply #8 on: January 17, 2010, 07:20:02 PM »
Oh.  Sorry.  I guess that doesn't work any more.  I would have checked it myself, but I can't see links in threads on theswamp when I'm browsing from my Blackberry.

Not a problem, thanks for your interest  :-)

Andrea

  • Water Moccasin
  • Posts: 2372
Re: BrowseForFolder Default Folder?
« Reply #9 on: January 18, 2010, 03:36:45 PM »
Hi Lee....

you can take a look in to..
http://wsh2.uw.hu/ch12f.html
under the options method..maybe this can help..

 :police:
Keep smile...

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: BrowseForFolder Default Folder?
« Reply #10 on: January 18, 2010, 03:41:16 PM »
Many thanks Andrea - I shall take a look!  :-)

Andrea

  • Water Moccasin
  • Posts: 2372
Re: BrowseForFolder Default Folder?
« Reply #11 on: September 06, 2015, 07:18:23 PM »
I know this is an old post..
but just for reference..


Code: [Select]
(setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))
(setq folder (vlax-invoke sh 'browseforfolder 0 "Browse" "&H2000" "c:\\test"))
(vlax-release-object sh)
Keep smile...

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: BrowseForFolder Default Folder?
« Reply #12 on: September 07, 2015, 05:32:50 AM »
I know this is an old post..
but just for reference..

Code: [Select]
(setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))
(setq folder (vlax-invoke sh 'browseforfolder 0 "Browse" "&H2000" "c:\\test"))
(vlax-release-object sh)

But by specifying the root folder argument, the user is unable to browse or select a folder above this directory.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: BrowseForFolder Default Folder?
« Reply #13 on: September 08, 2015, 05:19:06 PM »
This is all I could find Lee.

http://msdn.microsoft.com/en-us/library/bb774065%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/bb773205%28VS.85%29.aspx

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23384559.html
I can assist with that one at least, here is the necessary information that danaseaman posted:
Quote
BrowseForFolder supports both a RootDirectory and a StartDirectory but the Shell version only allows changing the RootDirectory. Using the API version you can set a callback in module that allows you to set the StartDirectory.

Option Explicit

Private Sub Form_Load()
   Debug.Print BrowseFolder(App.Path, "Browse For Folder")
Code: [Select]
Option Explicit
 
Private Const WM_USER      As Long = &H400&
' message from browser
Private Const BFFM_INITIALIZED      As Long = 1
Private Const BFFM_SELCHANGED       As Long = 2
Private Const BFFM_VALIDATEFAILEDA  As Long = 3 ' lParam:szPath ret:1(cont),0(EndDialog)
Private Const BFFM_VALIDATEFAILEDW  As Long = 4 ' lParam:wzPath ret:1(cont),0(EndDialog)
Private Const BFFM_IUNKNOWN         As Long = 5 ' provides IUnknown to client. lParam: IUnknown*
' messages to browser
Private Const BFFM_SETSTATUSTEXTA   As Long = (WM_USER + 100)
Private Const BFFM_ENABLEOK         As Long = (WM_USER + 101)
Private Const BFFM_SETSELECTIONA    As Long = (WM_USER + 102)
Private Const BFFM_SETSELECTIONW    As Long = (WM_USER + 103)
Private Const BFFM_SETSTATUSTEXTW   As Long = (WM_USER + 104)
Private Const BFFM_SETOKTEXT        As Long = (WM_USER + 105)          ' Unicode only
Private Const BFFM_SETEXPANDED      As Long = (WM_USER + 106)       ' Unicode only
 
Private Declare Function SHBrowseForFolderA Lib "shell32.dll" (ByRef lpbi As BROWSEINFO) As Long
Private Declare Function SHGetPathFromIDListA Lib "shell32" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SendMessageA Lib "user32.dll" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Private Declare Function SendMessageAsLong Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
 
Private Type BROWSEINFO
   hOwner               As Long
   pidlRoot             As Long
   pszDisplayName       As String
   lpszTitle            As String
   ulFlags              As Long
   lpfn                 As Long
   lParam               As Long
   iImage               As Long
End Type
 
Public Enum bif
   BIF_RETURNONLYFSDIRS = &H1        ' For finding a folder to start document searching
   BIF_DONTGOBELOWDOMAIN = &H2       ' For starting the Find Computer
   BIF_STATUSTEXT = &H4              ' Top of the dialog has 2 lines of text for BROWSEINFO.lpszTitle and one line if
   ' this flag is set.  Passing the message BFFM_SETSTATUSTEXTA to the hwnd can set the
   ' rest of the text.  This is not used with BIF_USENEWUI and BROWSEINFO.lpszTitle gets
   ' all three lines of text.
   BIF_RETURNFSANCESTORS = &H8
   BIF_EDITBOX = &H10                ' Add an editbox to the dialog
   BIF_VALIDATE = &H20               ' insist on valid result (or CANCEL)
 
   BIF_NEWDIALOGSTYLE = &H40         ' Use the new dialog layout with the ability to resize
   ' Caller needs to call OleInitialize() before using this API
 
   BIF_USENEWUI = (BIF_NEWDIALOGSTYLE Or BIF_EDITBOX)
 
   BIF_BROWSEINCLUDEURLS = &H80      ' Allow URLs to be displayed or entered. (Requires BIF_USENEWUI)
   BIF_UAHINT = &H100                ' Add a UA hint to the dialog, in place of the edit box. May not be combined with BIF_EDITBOX
   BIF_NONEWFOLDERBUTTON = &H200     ' Do not add the "New Folder" button to the dialog.  Only applicable with BIF_NEWDIALOGSTYLE.
   BIF_NOTRANSLATETARGETS = &H400    ' don't traverse target as shortcut
   BIF_BROWSEFORCOMPUTER = &H1000    ' Browsing for Computers.
   BIF_BROWSEFORPRINTER = &H2000     ' Browsing for Printers
   BIF_BROWSEINCLUDEFILES = &H4000   ' Browsing for Everything
   BIF_SHAREABLE = &H8000            ' sharable resources displayed (remote shares, requires BIF_USENEWUI)
End Enum
 
 
Public currDir As String
Const MAX_PATH = 260
 
Function BrowseFolder(StartDir As String, Optional Caption As String = "") As String
   Dim BROWSEINFO       As BROWSEINFO
   Dim FolderName       As String
   Dim ID               As Long
   Dim Res              As Long
   currDir = StartDir
 
   With BROWSEINFO
      .hOwner = 0
      .pidlRoot = 0
      .pszDisplayName = String$(MAX_PATH, vbNullChar)
      .lpszTitle = Caption
      .ulFlags = BIF_RETURNONLYFSDIRS
      .lpfn = GetAddressofFunction(AddressOf BrowseCallbackProc)  'get address of function.
      '.lParam =
   End With
 
   ID = SHBrowseForFolderA(BROWSEINFO)
   If ID Then
      FolderName = Space(MAX_PATH)
      SHGetPathFromIDListA ID, FolderName
      BrowseFolder = Left$(FolderName, InStr(FolderName, vbNullChar) - 1)
   Else
      BrowseFolder = ""
   End If
End Function
 
Public Function BrowseCallbackProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal lp As Long, ByVal pData As Long) As Long
'
   Dim ID               As Long
   Dim ret              As Long
   Dim sBuffer          As String
 
   On Error Resume Next  'Sugested by MS to prevent an error from
   'propagating back into the calling process.
 
   Select Case uMsg
 
      Case BFFM_INITIALIZED
         SendMessageA hWnd, BFFM_SETSELECTIONA, 1, ByVal currDir
 
      Case BFFM_SELCHANGED
         sBuffer = Space(MAX_PATH)
 
         ret = SHGetPathFromIDListA(lp, sBuffer)
         If ret = 1 Then
            Call SendMessageA(hWnd, BFFM_SETSTATUSTEXTA, 0, ByVal sBuffer)
         End If
 
   End Select
 
   BrowseCallbackProc = 0
End Function
 
' This function allows you to assign a function pointer to a vaiable.
Private Function GetAddressofFunction(add As Long) As Long
   GetAddressofFunction = add
End Function


Hopefully that will point you in the right direction at least.