Results 1 to 2 of 2

Thread: Common Dialog Control

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2002
    Posts
    3

    Common Dialog Control

    I work on VB 6.0. I am using common dialog control in an activeX control project.
    My problem is - I am using cdNExplorer flag so the dialog control gives winows explorer type display. Now with this I am able to select only files, Not a single folder.
    My purpose is to be able to select a single folder just like a file. But at present when I select folder & press ok it opens up the folder & shows all the files in that folder.
    So what do I need to do to be able to select a single folder just like a single file?
    Can anybody help me?

  2. #2
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    You'd probably be better off using the browse for folders dialog. Here's a module for it:

    VB Code:
    1. Option Explicit
    2. Private Type BrowseInfo
    3.     hWndOwner As Long
    4.     pIDLRoot As Long
    5.     pszDisplayName As Long
    6.     lpszTitle As Long
    7.     ulFlags As Long
    8.     lpfnCallback As Long
    9.     lParam As Long
    10.     iImage As Long
    11. End Type
    12. Public Enum BIF_Flags
    13.     BIF_BROWSEFORCOMPUTER = &H1000
    14.     BIF_BROWSEFORPRINTER = &H2000
    15.     BIF_BROWSEINCLUDEFILES = &H4000
    16.     BIF_BROWSEINCLUDEURLS = &H80
    17.     BIF_DONTGOBELOWDOMAIN = &H2
    18.     BIF_EDITBOX = &H10
    19.     BIF_NEWDIALOGSTYLE = &H40
    20.     BIF_RETURNFSANCESTORS = &H8
    21.     BIF_RETURNONLYFSDIRS = &H1
    22.     BIF_SHAREABLE = &H8000
    23.     BIF_STATUSTEXT = &H4
    24.     BIF_USENEWUI = &H40
    25.     BIF_VALIDATE = &H20
    26. End Enum
    27. Private Const MAX_PATH = 260
    28. Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
    29. Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
    30. Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
    31. Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
    32.  
    33. Public Function GetFolder(ByVal hWnd As Long, _
    34.     Optional ByVal Message As String = "Please select the folder:", _
    35.     Optional ByVal Flags As BIF_Flags = BIF_RETURNONLYFSDIRS) As String
    36.     On Error Resume Next
    37.     Dim ReturnValue As Long
    38.     Dim BrowseOptions As BrowseInfo
    39.  
    40.     'Options for the dialog
    41.     With BrowseOptions
    42.         'Owner window
    43.         .hWndOwner = hWnd
    44.         'lstrcat appends the two strings and returns the memory address
    45.         .lpszTitle = lstrcat(Message, "")
    46.         'Set the flags
    47.         .ulFlags = BIF_Flags
    48.     End With
    49.  
    50.     'Show the Browse for folder dialog
    51.     ReturnValue = SHBrowseForFolder(BrowseOptions)
    52.     'If Cancel was not choosen
    53.     If ReturnValue Then
    54.         'Convert the return value to a string
    55.         GetFolder = String$(MAX_PATH, 0)
    56.         'To the path into GetFolder's return value
    57.         Call SHGetPathFromIDList(ReturnValue, GetFolder)
    58.         'Free memory used by the dialog
    59.         CoTaskMemFree ReturnValue
    60.         'Remove vbNullChartext after folder
    61.         ReturnValue = InStr(GetFolder, vbNullChar)
    62.         'If there is more text remove it
    63.         If ReturnValue Then GetFolder = Left$(GetFolder, ReturnValue - 1)
    64.     End If
    65. End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width