Tips:ฟังก์ชั่น API เพื่อหาโฟลเดอร์พิเศษเช่น My Document ฯลฯ (VB6)
posted on 13 Sep 2008 22:53 by theera in TipDeclare Function SHGetSpecialFolderLocation Lib "Shell32.dll" _
(ByVal hwndOwner As Long, ByVal nFolder As Long, _
pidl As ITEMIDLIST) As Long
Declare Function SHGetPathFromIDList Lib "Shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long
Public Type SH_ITEMID
cb As Long
abID As Byte
End Type
Public Type ITEMIDLIST
mkid As SH_ITEMID
End Type
' The Desktop - virtual folder
Public Const CSIDL_DESKTOP = &H0
' Program Files
Public Const CSIDL_PROGRAMS = 2
' Control Panel - virtual folder
Public Const CSIDL_CONTROLS = 3
' Printers - virtual folder
Public Const CSIDL_PRINTERS = 4
' My Documents
Public Const CSIDL_DOCUMENTS = 5
' Favorites
Public Const CSIDL_FAVORITES = 6
' Startup Folder
Public Const CSIDL_STARTUP = 7
' Recent Documents
Public Const CSIDL_RECENT = 8
' Send To Folder
Public Const CSIDL_SENDTO = 9
' Recycle Bin - virtual folder
Public Const CSIDL_BITBUCKET = 10
' Start Menu
Public Const CSIDL_STARTMENU = 11
' Desktop folder
Public Const CSIDL_DESKTOPFOLDER = 16
' My Computer - virtual folder
Public Const CSIDL_DRIVES = 17
' Network Neighbourhood - virtual folder
Public Const CSIDL_NETWORK = 18
' NetHood Folder
Public Const CSIDL_NETHOOD = 19
' Fonts folder
Public Const CSIDL_FONTS = 20
' ShellNew folder
Public Const CSIDL_SHELLNEW = 21
Public Const MAX_PATH As Integer = 260
Public Function fGetSpecialFolder(CSIDL As Long) As String
Dim sPath As String
Dim IDL As ITEMIDLIST
'
' Retrieve info about system folders such as the
' "Desktop" folder. Info is stored in the IDL structure.
'
fGetSpecialFolder = ""
If SHGetSpecialFolderLocation(Form1.hWnd, CSIDL, IDL) = 0 Then
'
' Get the path from the ID list, and return the folder.
'
sPath = Space$(MAX_PATH)
If SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath) Then
fGetSpecialFolder = Left$(sPath, InStr(sPath, vbNullChar) - 1) & "\"
End If
End If
End Function
'//--- Sample
Debug.Print "Desktop Folder " & fGetSpecialFolder(CSIDL_DESKTOPFOLDER)

#1 By โหลดเพลง (124.157.236.250) on 2009-08-28 08:00