Results 1 to 3 of 3

Thread: Common Dialog

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    21

    Question Common Dialog

    Hello,

    I was curious if anyone knew a way to use the common dialog control to open a specific folder's contents.

    In example: Once the user clicks on the specified folder - all
    contents of that folder are added to a listbox and/ or
    file listbox.

    I have already done this using the drive, directory, and folder objects - but would like to clean the program up by the previous method.

    Is this possible?!?!

    My Appreciation

    ---J---

  2. #2
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    How's about you use the browser for folders dialog instead:

    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 = 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

    Then just use DIR from the return value, something like this:

    VB Code:
    1. Dim strFolder As String
    2. strFolder = GetFolder(Me.hWnd)
    3. Dim strFile As String
    4. strFile = Dir(strFolder)
    5. Do While strFile <> vbNullString
    6.     List1.AddItem strFile
    7.     strFile = Dir
    8. Loop

    (last bit is untested but I think it should work)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    21
    Thank you will try that...

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