home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / zkuste / vbasic / Data / Utils / XZipComp.exe / XceedEncoding.Cab / F112902_BrowseFolderModule.bas < prev    next >
Encoding:
BASIC Source File  |  2001-04-06  |  5.4 KB  |  139 lines

  1. Attribute VB_Name = "BrowseFolderModule"
  2. ' Xceed Binary Encoding Library - Encoding Manager sample
  3. ' Copyright (c) 2001 Xceed Software Inc.
  4. '
  5. ' [BrowseFolderModule.bas]
  6. '
  7. ' This module contains code that implements the SHBrowseForFolder API.
  8. '
  9. ' This file is part of the Xceed Binary Encoding Library sample applications.
  10. ' The source code in this file is only intended as a supplement to Xceed
  11. ' Binary Encoding Library's documentation, and is provided "as is", without
  12. ' warranty of any kind, either expressed or implied.
  13.  
  14. Option Explicit
  15.  
  16. Private Declare Function SHBrowseForFolder Lib "Shell32" _
  17.                                   (lpbi As BrowseInfo) As Long
  18.  
  19. Private Declare Function SHGetPathFromIDList Lib "Shell32" _
  20.                                   (ByVal pidList As Long, _
  21.                                   ByVal lpBuffer As String) As Long
  22.  
  23. Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" _
  24.                                   (ByVal lpString1 As String, ByVal _
  25.                                   lpString2 As String) As Long
  26.  
  27. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
  28.                                   (ByVal hwnd As Long, _
  29.                                   ByVal wMsg As Long, _
  30.                                   ByVal wParam As Long, _
  31.                                   lParam As Any) As Long
  32.  
  33. Public Declare Function GetLastError Lib "kernel32" () As Long
  34.  
  35.  
  36. Private Const BIF_RETURNONLYFSDIRS = &H1      ' For finding a folder to start document searching
  37. Private Const BIF_DONTGOBELOWDOMAIN = &H2     ' For starting the Find Computer
  38. Private Const BIF_STATUSTEXT = &H4            ' Top of the dialog has 2 lines of text for BROWSEINFO.lpszTitle and one line if
  39.                                               ' this flag is set.  Passing the message BFFM_SETSTATUSTEXTA to the hwnd can set the
  40.                                               ' rest of the text.  This is not used with BIF_USENEWUI and BROWSEINFO.lpszTitle gets
  41.                                               ' all three lines of text.
  42. Private Const BIF_RETURNFSANCESTORS = &H8
  43. Private Const BIF_EDITBOX = &H10              ' Add an editbox to the dialog
  44. Private Const BIF_VALIDATE = &H20             ' insist on valid result (or CANCEL)
  45.  
  46. Private Const BIF_NEWDIALOGSTYLE = &H40       ' Use the new dialog layout with the ability to resize
  47.                                               ' Caller needs to call OleInitialize() before using this API
  48.  
  49. Private Const BIF_USENEWUI = (BIF_NEWDIALOGSTYLE Or BIF_EDITBOX)
  50.  
  51. Private Const BIF_BROWSEINCLUDEURLS = &H80    ' Allow URLs to be displayed or entered. (Requires BIF_USENEWUI)
  52.  
  53. Private Const BIF_BROWSEFORCOMPUTER = &H1000  ' Browsing for Computers.
  54. Private Const BIF_BROWSEFORPRINTER = &H2000   ' Browsing for Printers
  55. Private Const BIF_BROWSEINCLUDEFILES = &H4000 ' Browsing for Everything
  56. Private Const BIF_SHAREABLE = &H8000          ' sharable resources displayed (remote shares, requires BIF_USENEWUI)
  57.  
  58. Private Const MAX_PATH = 260
  59.  
  60. ' message from browser
  61. Private Const BFFM_INITIALIZED = 1
  62. Private Const BFFM_SELCHANGED = 2
  63. Private Const BFFM_VALIDATEFAILEDA = 3   ' lParam:szPath ret:1(cont),0(EndDialog)
  64. Private Const BFFM_VALIDATEFAILEDW = 4   ' lParam:wzPath ret:1(cont),0(EndDialog)
  65.  
  66. ' message to browser
  67. Private Const WM_USER = &H400
  68. Private Const BFFM_SETSTATUSTEXTA = (WM_USER + 100)
  69. Private Const BFFM_ENABLEOK = (WM_USER + 101)
  70. Private Const BFFM_SETSELECTIONA = (WM_USER + 102)
  71. Private Const BFFM_SETSELECTIONW = (WM_USER + 103)
  72. Private Const BFFM_SETSTATUSTEXTW = (WM_USER + 104)
  73.  
  74. Private Type BrowseInfo
  75.    hWndOwner      As Long
  76.    pIDLRoot       As Long
  77.    pszDisplayName As Long
  78.    lpszTitle      As Long
  79.    ulFlags        As Long
  80.    lpfnCallback   As Long
  81.    lParam         As Long
  82.    iImage         As Long
  83. End Type
  84.  
  85. Private m_sFolderSelected As String
  86.  
  87. Public Function BrowseFolder(ByVal hwnd As Long, _
  88.                              ByVal sTitle As String, _
  89.                              ByRef sFolder As String) As Boolean
  90.  
  91.     Dim lpIDList As Long
  92.     Dim sBuffer As String
  93.     Dim xBrowseInfo As BrowseInfo
  94.  
  95.     m_sFolderSelected = sFolder
  96.     
  97.     With xBrowseInfo
  98.         .hWndOwner = hwnd
  99.         .lpszTitle = lstrcat(sTitle, "")
  100.         .lpfnCallback = Address(AddressOf BrowseCallbackProc)
  101.         .ulFlags = BIF_RETURNONLYFSDIRS
  102.     End With
  103.  
  104.     lpIDList = SHBrowseForFolder(xBrowseInfo)
  105.  
  106.     If lpIDList Then
  107.         sBuffer = Space(MAX_PATH)
  108.         Call SHGetPathFromIDList(lpIDList, sBuffer)
  109.         sFolder = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
  110.         m_sFolderSelected = sFolder
  111.         BrowseFolder = True
  112.     Else
  113.         BrowseFolder = False
  114.     End If
  115.  
  116. End Function
  117.  
  118. Private Function BrowseCallbackProc(ByVal hwnd As Long, _
  119.                                     ByVal uMsg As Integer, _
  120.                                     ByVal lParam As Long, _
  121.                                     ByVal lpData As Long) As Integer
  122.  
  123.     Select Case uMsg
  124.         Case BFFM_INITIALIZED
  125.             Call SendMessage(hwnd, BFFM_SETSELECTIONA, 1, ByVal m_sFolderSelected)
  126.             
  127.         Case BFFM_SELCHANGED
  128.             'Call SendMessage(hwnd, BFFM_ENABLEOK, 0, ByVal 0)
  129.     End Select
  130.     BrowseCallbackProc = 0
  131.  
  132. End Function
  133.  
  134. Private Function Address(lAddressIn As Long) As Long
  135.     
  136.     Address = lAddressIn
  137.  
  138. End Function
  139.