Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browse Folder Control in vb6? 4

Status
Not open for further replies.

rahmanjan

Programmer
Apr 13, 2003
180
AU
hi all,

I want to enable users to click a button and then browse the the list of drives and folders in their computer. The same way it is done in Win-98-> Find -> Browse

My question is that: is there any control in VB6 to handle the same thing? Or do i have to write such a control? or can i use that control available by windows?

regards
 
Take a look at the drive, directory, and file listbox controls that are included with VB.

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
Hi Yamjan,

I think there is a way to work with the Common Dialog and have it show folders only. I'm not sure how to do that, though.

Should you be interested, I have written a procedure that does precisely what you want: let the user select a FOLDER, and let him/her create or delete folders in the process.

Let me know if you are interested; the procedure is (way) too large to post here. If I get round to it, I will put it on my website and post a link to it here tonight.

Regards,
Marco

 
Hi Yamjan,

I don't know if my procedure is needed or even useful at this point, but here it is anyway (a zipped visual basic project):


--it's mostly Dutch, though... but it shows a form with a drivelist and a folderlist. I use a modified version of my procedure to set the drive and folder prior to showing the form.

Regards,
Marco
 
Yamjan,
Your code works great but now I need to be able to create new folders from the same browser.
 
I think my code has a 'create folder' button which you can use to do so. But this is too obvious; you probably mean something else. Can you be more specific?

Marco

members.lycos.nl\mchokke
 
You can also go to the Common Controls Replacement Project web site, and download their 'browse dialog' and 'browse dialog server' ocx controls. They are basically improved Microsoft controls. They are free and come with demo projects.

Thanks and Good Luck!

zemp
 
Everybody always wants to do this the hard way... here's a significant revision of my previously posted code on obtaining the paths to the various Windows special folders. As with that you'll need to add a reference to the Microsoft Shell Controls and Automation library (SHDOC401.DLL):
[tt]
Option Explicit

'BROWSEINFO Flag values:
Private Enum BIFS
BIF_RETURNONLYFSDIRS = &H1 'Only returns file system directories
BIF_DONTGOBELOWDOMAIN = &H2 'Does not include network folders below domain level
BIF_STATUSTEXT = &H4 'Includes status area in the dialog for use with callback
BIF_RETURNFSANCESTORS = &H8 'Only returns file system ancestors.
BIF_EDITBOX = &H10 'allows user to rename selection
BIF_VALIDATE = &H20 'insist on valid editbox result (or CANCEL)
BIF_USENEWUI = &H40 'Version 5.0 or later of Shell32.dll. Use the new user-interface. Setting
'this flag provides the user with a larger dialog box
'that can be resized. It has several new capabilities
'including: drag and drop capability within the
'dialog box, reordering, context menus, new folders,
'delete, and other context menu commands. To use
'this flag, you must call OleInitialize or
'CoInitialize before calling SHBrowseForFolder.
BIF_BROWSEFORCOMPUTER = &H1000 'Only returns computers.
BIF_BROWSEFORPRINTER = &H2000 'Only returns printers.
BIF_BROWSEINCLUDEFILES = &H4000 'Browse for everything
End Enum


' SHDOC32 has a reliance on Shell32.dll - this generally needs to be at least version 4.71
' or later for most of the Shell32 tricks to work
Private Function vbBrowseForFolder(Optional strRoot As String, Optional BIF_Flags As BIFS = 0) As String
Dim myFolder As Shell32.Folder

With New Shell32.Shell
Set myFolder = .BrowseForFolder(Form1.hWnd, "Select folder", BIF_Flags, strRoot)
If Not myFolder Is Nothing Then vbBrowseForFolder = myFolder.ParentFolder.ParseName(myFolder.Title).Path
End With
End Function


 
strongm,

I set the constants and everything up right, this works if you drill down through the drives such as C:\Dir\Test
but if you select a folder such as 'My Documents' it errors out at the highlighted point below... with an Object Not Set error.

Code:
Private Function vbBrowseForFolder(Optional strRoot As String, Optional BIF_Flags As BIFS = 0) As String
  Dim myFolder As Shell32.Folder, myPath As FolderItem
  With New Shell32.Shell
    Set myFolder = .BrowseForFolder(Form1.hWnd, "Select folder", BIF_Flags, strRoot)
    If Not myFolder Is Nothing Then
      Set myPath = myFolder.ParentFolder.ParseName(myFolder.Title)
[b][COLOR=red]      vbBrowseForFolder = myPath.Path[/color][/b]
    Else
      vbBrowseForFolder = strRoot
    End If
 End With
End Function

What do I need to do to correct this?

Is the a BIF flag that needs to be set to enable the path translation?

Also if you pass a path as an argument in the strRoot param, It sets that path as the root path and does not let you navigate up from it.

Thanks,
Josh

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
<oops, meant to answer this ages ago>

No, it's just I provided a 'significant revision' of my code, so significant that it cannot actually return a special folder because it doesn't know how to parse it into a proper name. So...the following should fix it...
Code:
[COLOR=blue]
Option Explicit


'BROWSEINFO Flag values:
Private Enum BIFS
    BIF_RETURNONLYFSDIRS = &H1      'Only returns file system directories
    BIF_DONTGOBELOWDOMAIN = &H2     'Does not include network folders below domain level
    BIF_STATUSTEXT = &H4            'Includes status area in the dialog for use with callback
    BIF_RETURNFSANCESTORS = &H8     'Only returns file system ancestors.
    BIF_EDITBOX = &H10              'allows user to rename selection
    BIF_VALIDATE = &H20             'insist on valid editbox result (or CANCEL)
    BIF_USENEWUI = &H40             'Version 5.0 or later of Shell32.dll. Use the new user-interface. Setting
                                    'this flag provides the user with a larger dialog box
                                    'that can be resized. It has several new capabilities
                                    'including: drag and drop capability within the
                                    'dialog box, reordering, context menus, new folders,
                                    'delete, and other context menu commands. To use
                                    'this flag, you must call OleInitialize or
                                    'CoInitialize before calling SHBrowseForFolder.
    BIF_BROWSEFORCOMPUTER = &H1000  'Only returns computers.
    BIF_BROWSEFORPRINTER = &H2000   'Only returns printers.
    BIF_BROWSEINCLUDEFILES = &H4000 'Browse for everything
End Enum


' SHDOC32 has a reliance on Shell32.dll - this generally needs to be at least version 4.71
' or later for most of the Shell32 tricks to work
Private Function vbBrowseForFolder(Optional strRoot As String, Optional BIF_Flags As BIFS = 0) As String
    Dim myFolder As Shell32.Folder
        
    With New Shell32.Shell
        Set myFolder = .BrowseForFolder(Form1.hWnd, "Select folder", BIF_Flags, strRoot)
        If Not myFolder Is Nothing Then vbBrowseForFolder = GetSpecialPath(myFolder)  '.ParentFolder.ParseName(myFolder.Title).Path
   End With
End Function


' vDir can be either one of the ShellSpecialFolder constants (start with ssf), or a normal path string
Public Function GetSpecialPath(vDir As Variant) As String  'ShellSpecialFolderConstants) As String
    ' Requires reference to Microsoft Shell Controls and Automation (SHDOC401.dll or Shell32.dll depending on OS version)
    With New Shell32.Shell
        ' Should work for almost all versions of Shell32.dll (versions 4.71 and later on W95, W98)
        ' GetSpecialPath = .NameSpace(vdir).ParentFolder.ParseName(.NameSpace(vdir).Title).Path
        ' If you have shell32.dll version 5.0 or later (XP, W2000, Windows Me) you MUST use the following instead:
         GetSpecialPath = .NameSpace(vDir).Self.Path
    End With

End Function
[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top