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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Network Folder

Status
Not open for further replies.

Gianricus

Programmer
Apr 2, 2003
62
0
0
IT
hi,
I use usually dirlistbox for my app, but now i have one big problem!
Exist one object similar with that i can view my network?
With a Dirlistbox Object i don't view that.

I want scan my folder & subfolder

By & tks
 
Drop this into a module:


Option Explicit

Public Type BrowseInfo '//Used while launching the folder browser.
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

Private Const BFFM_INITIALIZED As Long = 1
Private Const BIF_RETURNONLYFSDIRS As Long = 1
Private Const BIF_DONTGOBELOWDOMAIN As Long = 2
Private Const WM_USER As Long = &H400
Private Const BFFM_SETSELECTION As Long = (WM_USER + 102)

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) 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 Function GetAddressofFunction(ByVal vlngAddress As Long) As Long
'//With this side-step it is possible to assign the address of a function to a variable (which is NOT directly possible in VB).

GetAddressofFunction = vlngAddress
End Function



Public Function GetFolder(ByVal hWnd As Long, ByVal vstrTitle As String, Optional ByVal lParam As Long = 0) As String
'//Launch the folder browser dialog and return the selected folder.
Dim lpIDList As Long
Dim strBuffer As String
Dim udtInfo As BrowseInfo

'//Prepare browser:
With udtInfo
.hWndOwner = hWnd
.lpszTitle = lstrcat(vstrTitle, "") '//We need a pointer to the string, which is possible by using this little side-step.
.ulFlags = BIF_RETURNONLYFSDIRS Or BIF_DONTGOBELOWDOMAIN
If lParam > 0 Then
.lParam = lParam
.lpfnCallback = GetAddressofFunction(AddressOf CallBack) '//It is NOT possible to directly assign the address of a function to a variable in VB.
End If
End With

'//Launch browser:
lpIDList = SHBrowseForFolder(udtInfo)

'//Retrieve selected folder:
If lpIDList > 0 Then
strBuffer = Space(255)
If SHGetPathFromIDList(lpIDList, strBuffer) > 0 Then strBuffer = Left(strBuffer, InStr(strBuffer, vbNullChar) - 1)
End If

'//Return selected folder:
GetFolder = strBuffer
End Function



Public Function GetFolder(ByVal hWnd As Long, ByVal vstrTitle As String, Optional ByVal lParam As Long = 0) As String
'//Launch the folder browser dialog and return the selected folder.
Dim lpIDList As Long
Dim strBuffer As String
Dim udtInfo As BrowseInfo

'//Prepare browser:
With udtInfo
.hWndOwner = hWnd
.lpszTitle = lstrcat(vstrTitle, "") '//We need a pointer to the string, which is possible by using this little side-step.
.ulFlags = BIF_RETURNONLYFSDIRS Or BIF_DONTGOBELOWDOMAIN
If lParam > 0 Then
.lParam = lParam
.lpfnCallback = GetAddressofFunction(AddressOf CallBack) '//It is NOT possible to directly assign the address of a function to a variable in VB.
End If
End With

'//Launch browser:
lpIDList = SHBrowseForFolder(udtInfo)

'//Retrieve selected folder:
If lpIDList > 0 Then
strBuffer = Space(255)
If SHGetPathFromIDList(lpIDList, strBuffer) > 0 Then strBuffer = Left(strBuffer, InStr(strBuffer, vbNullChar) - 1)
End If

'//Return selected folder:
GetFolder = strBuffer
End Function



Private Function CallBack(ByVal hWnd As Long, ByVal uMsg As Long, ByVal lParam As Long, ByVal lpData As Long) As Long
'//Callback for the folder browser.
Dim strFolder As String

If uMsg = BFFM_INITIALIZED Then
Select Case lpData
Case SET_ORG
strFolder = GetSetting("Windiff Launcher", "Settings", "Org Path", "C:\")
Case SET_EDITED
strFolder = GetSetting("Windiff Launcher", "Settings", "Edited Path", "C:\")
End Select

'//Set starting position of folder browser:
SendMessage hWnd, BFFM_SETSELECTION, 1, strFolder
End If

CallBack = 0
End Function



It'll show the standard window path browser dialog (which includes network support).

Greetings,
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top