Programming/Visual Basice

[VB] Folder Dialog

Foolishdevil 2010. 10. 28. 15:55

파일을 읽어오는 dialog 대신... Fodler을 가져오는 dialog입니다.
열심히 찾아서 프로젝트 반영은 해봤지만.. 잘 모르겠다는거........

다들 열프하세여;;

출처 : http://www.developer.com/net/vb/article.php/1541831/VB-TIP-Using-the-Browse-Folder-Dialog-Box.htm

Option Explicit

Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_DONTGOBELOWDOMAIN = 2
Private Const MAX_PATH = 260

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 Declare Function lstrcat Lib "kernel32" _
Alias "lstrcatA" (ByVal lpString1 As String, ByVal _
lpString2 As String) As Long

Private Type BrowseInfo
   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 Sub Command1_Click()
'Opens a Browse Folders Dialog Box that displays the 
'directories in your computer
Dim lpIDList As Long ' Declare Varibles
Dim sBuffer As String
Dim szTitle As String
Dim tBrowseInfo As BrowseInfo

szTitle = "Hello World. Click on a directory and " & _
"it's path will be displayed in a message box"
' Text to appear in the the gray area under the title bar
' telling you what to do

With tBrowseInfo
   .hWndOwner = Me.hWnd ' Owner Form
   .lpszTitle = lstrcat(szTitle, "")
   .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
End With

lpIDList = SHBrowseForFolder(tBrowseInfo)

If (lpIDList) Then
   sBuffer = Space(MAX_PATH)
   SHGetPathFromIDList lpIDList, sBuffer
   sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
   MsgBox sBuffer
End If

End Sub


실행하면 아래와 같은 그림이 나타나게 됩니다.


속성 값 중에서 pIDLRoot 라는 값으로 Root의 위치를 지정해 줄 수 있지만... 엉뚱한 곳으로 갑니다.. 
0 : 내컴퓨터
1 : Internet Expoloer
2 : 시작메뉴 -> 프로그램목록
3 : 제어판
4 : 프린터 및 팩스
5 : 내문서
6 : 즐겨찾기
7 : 시작프로그램
8 : 내 최근 문서
9 : SendTo
10 : 휴지통
11 : 시작메뉴
12 : ... 사용자 설정값인듯......
.... 
숫자 형식이므로 .... 숫자로 제어할 수 있습니다. 출처는 위의 링크에서..