...

View Full Version : Browseforfolders in Visual Basic



aning
12-21-2004, 09:07 AM
The code below is a Browseforfolders script. It does what it is suppose to but the location always loses once the application is closed. I would like the user to specify one location or whatever and wants the form to remember the location previously chosen when it is open again....
_____________________________
Option Explicit

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

Private Const BIF_RETURNONLYFSDIRS = &H1
Private Const BIF_DONTGOBELOWDOMAIN = &H2
Private Const BIF_STATUSTEXT = &H4
Private Const BIF_RETURNFSANCESTORS = &H8
Private Const BIF_BROWSEFORCOMPUTER = &H1000
Private Const BIF_BROWSEFORPRINTER = &H2000
Private Const MAX_PATH = 260

Private Declare Function SHGetPathFromIDList Lib "shell32" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long

Private Declare Sub CoTaskMemFree Lib "ole32" _
(ByVal pv As Long)



Private Sub Command1_Click()

Dim bi As BROWSEINFO
Dim pidl As Long
Dim path As String
Dim pos As Long

Label1.Caption = ""


With bi
.hOwner = Me.hWnd

.pidlRoot = 0&

.lpszTitle = "Select your Windows\System\ directory"

.ulFlags = BIF_RETURNONLYFSDIRS
End With

pidl = SHBrowseForFolder(bi)
path = Space$(MAX_PATH)

If SHGetPathFromIDList(ByVal pidl, ByVal path) Then
pos = InStr(path, Chr$(0))
Label1.Caption = Left(path, pos - 1)
End If

Call CoTaskMemFree(pidl)

End Sub
______________________

and also how do i add this command to the form... being a newbie, i can't figure it out....the script is actually a part of my little program

______________________
Private Sub Command1_Click()
Bitmapfiletosave ("filename.ext")
End Sub
_______________

shmoove
12-21-2004, 09:53 AM
You can use SaveSetting when you exit the program to save the information in the registry and GetSetting when you load to retrieve it from there.

shmoove



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum