Solved

MS Cmn Dialog Box openig directories only

Posted on 2001-06-06
6
148 Views
Last Modified: 2010-05-02
Hia,
I want my ms common dialog box to return the directory selected, rather than force me to select a file. How can I do that, is there a flag or something I can apply?

Thanks,
Nite
0
Comment
Question by:NiTech
6 Comments
 
LVL 10

Expert Comment

by:caraf_g
ID: 6159134
Yeah. The "Common Dialog Replacement Project" is just the place to look for:

http://www.mvps.org/ccrp/controls/ccrpcontrols.htm

The one you'll be interested in is the BrowseDialog. I personally prefer the server over the OCX.

It has the control, plus code samples!
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 6159137
Actually, the OCX has been discontinued. :o)
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6159138
Or you can use the API SHBrowseForFolder dialog instead:

Private Type BrowseInfo
    hWndOwner As Long
    pIDLRoot As Long
    pszDisplayName As Long
    lpszTitle As Long
    ulFlags As Long
    lpfnCallback As Long
    lParam As Long
    iImage As Long
End Type
Const BIF_RETURNONLYFSDIRS = 1
Const MAX_PATH = 260
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'KPDTeam@Allapi.net
    Dim iNull As Integer, lpIDList As Long, lResult As Long
    Dim sPath As String, udtBI As BrowseInfo

    With udtBI
        'Set the owner window
        .hWndOwner = Me.hWnd
        'lstrcat appends the two strings and returns the memory address
        .lpszTitle = lstrcat("C:\", "")
        'Return only if the user selected a directory
        .ulFlags = BIF_RETURNONLYFSDIRS
    End With

    'Show the 'Browse for folder' dialog
    lpIDList = SHBrowseForFolder(udtBI)
    If lpIDList Then
        sPath = String$(MAX_PATH, 0)
        'Get the path from the IDList
        SHGetPathFromIDList lpIDList, sPath
        'free the block of memory
        CoTaskMemFree lpIDList
        iNull = InStr(sPath, vbNullChar)
        If iNull Then
            sPath = Left$(sPath, iNull - 1)
        End If
    End If

    MsgBox sPath
End Sub

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Expert Comment

by:caraf_g
ID: 6159144
Here's the "programmer's reference"

http://www.mvps.org/ccrp/support/help/bdsvr/ccrpbds.htm

Tim,

Your example works, but I found it very finicky to customize it to behave exactly the way you want it. With the CCRP solution that's made very easy.
0
 
LVL 27

Accepted Solution

by:
Ark earned 50 total points
ID: 6172731
Hi

Const BIF_RETURNONLYFSDIRS = &H1
Const BIF_DONTGOBELOWDOMAIN = &H2
Const BIF_INCLUDEFILES = &H4000&
Const BIF_EDITBOX = &H10

Private Sub Command1_Click()
  Dim oShell As Object
  Set oShell = CreateObject("Shell.Application")
  On Error Resume Next
  Caption = oShell.BrowseForFolder(0, "Choose a folder", BIF_RETURNONLYFSDIRS)
  If Err Then Caption = "Nothing selected"
  Set oShell = Nothing
End Sub

Cheers
0
 

Author Comment

by:NiTech
ID: 6455998
Thanks, sorry for late response.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now