SHBrowseForFolder这个函数可以弹出一个文件夹选择窗而返回PIDL,但这不是我所需要的功能。我希望有这样的函数:
function GetPIDLfromPath(byval sPath as string ) as long 提供路径名称,然后返回PIDL
function GetPIDLfromPath(byval sPath as string ) as long 提供路径名称,然后返回PIDL
1.对于Special Folder,比较容易。直接用Call SHGetSpecialFolderLocation(0, CSIDL, lPIDL)。
2.对于一般Folder,用ILCreateFromPathW。Private Declare Function ILCreateFromPathW Lib "shell32" (ByVal pwszPath As Long) As Long
#If WIN32_IE >= &H500 Then
Private Declare Sub ILFree Lib "shell32" (ByVal pidl As Long)
#Esle
Private Declare Sub ILFree Lib "shell32" Alias "#155" (ByVal pidl As Long)
#End If
Public Function GetPIDLFromPath(hWnd As Long, sPath As String) As Long
GetPIDLFromPath = ILCreateFromPathW(StrPtr(sPath))
End Function
调用:
pidl = GetPIDLFromPath(Me.hWnd, sPath)
ILFree pidl
pidl = 0不知我理解对不对。敬请参考。
CSIDL_DESKTOP = &H0 ' <desktop>
CSIDL_INTERNET = &H1 ' Internet Explorer (icon on desktop)
CSIDL_PROGRAMS = &H2 ' Start Menu\Programs
CSIDL_CONTROLS = &H3 ' My Computer\Control Panel
CSIDL_PRINTERS = &H4 ' My Computer\Printers
CSIDL_PERSONAL = &H5 ' My Documents
CSIDL_FAVORITES = &H6 ' <user name>\Favorites
CSIDL_STARTUP = &H7 ' Start Menu\Programs\Startup
CSIDL_RECENT = &H8 ' <user name>\Recent
CSIDL_SENDTO = &H9 ' <user name>\SendTo
CSIDL_BITBUCKET = &HA ' <desktop>\Recycle Bin
CSIDL_STARTMENU = &HB ' <user name>\Start Menu
CSIDL_MYDOCUMENTS = &HC ' logical "My Documents" desktop icon
CSIDL_MYMUSIC = &HD ' "My Music" folder
CSIDL_MYVIDEO = &HE ' "My Videos" folder
CSIDL_DESKTOPDIRECTORY = &H10 ' <user name>\Desktop
CSIDL_DRIVES = &H11 ' My Computer
CSIDL_NETWORK = &H12 ' Network Neighborhood (My Network Places)
CSIDL_NETHOOD = &H13 ' <user name>\nethood
CSIDL_FONTS = &H14 ' windows\fonts
CSIDL_TEMPLATES = &H15
CSIDL_COMMON_STARTMENU = &H16 ' All Users\Start Menu
CSIDL_COMMON_PROGRAMS = &H17 ' All Users\Start Menu\Programs
CSIDL_COMMON_STARTUP = &H18 ' All Users\Startup
CSIDL_COMMON_DESKTOPDIRECTORY = &H19 ' All Users\Desktop
CSIDL_APPDATA = &H1A ' <user name>\Application Data
CSIDL_PRINTHOOD = &H1B ' <user name>\PrintHood
CSIDL_LOCAL_APPDATA = &H1C ' <user name>\Local Settings\Applicaiton Data (non roaming)
CSIDL_ALTSTARTUP = &H1D ' non localized startup
CSIDL_COMMON_ALTSTARTUP = &H1E ' non localized common startup
CSIDL_COMMON_FAVORITES = &H1F
CSIDL_INTERNET_CACHE = &H20
CSIDL_COOKIES = &H21
CSIDL_HISTORY = &H22
CSIDL_COMMON_APPDATA = &H23 ' All Users\Application Data
CSIDL_WINDOWS = &H24 ' GetWindowsDirectory()
CSIDL_SYSTEM = &H25 ' GetSystemDirectory()
CSIDL_PROGRAM_FILES = &H26 ' C:\Program Files
CSIDL_MYPICTURES = &H27 ' C:\Program Files\My Pictures
CSIDL_PROFILE = &H28 ' USERPROFILE
CSIDL_SYSTEMX86 = &H29 ' x86 system directory on RISC
CSIDL_PROGRAM_FILESX86 = &H2A ' x86 C:\Program Files on RISC
CSIDL_PROGRAM_FILES_COMMON = &H2B ' C:\Program Files\Common
CSIDL_PROGRAM_FILES_COMMONX86 = &H2C ' x86 Program Files\Common on RISC
CSIDL_COMMON_TEMPLATES = &H2D ' All Users\Templates
CSIDL_COMMON_DOCUMENTS = &H2E ' All Users\Documents
CSIDL_COMMON_ADMINTOOLS = &H2F ' All Users\Start Menu\Programs\Administrative Tools
CSIDL_ADMINTOOLS = &H30 ' <user name>\Start Menu\Programs\Administrative Tools
CSIDL_CONNECTIONS = &H31 ' Network and Dial-up Connections
CSIDL_COMMON_MUSIC = &H35 ' All Users\My Music
CSIDL_COMMON_PICTURES = &H36 ' All Users\My Pictures
CSIDL_COMMON_VIDEO = &H37 ' All Users\My Video
CSIDL_RESOURCES = &H38 ' Resource Direcotry
CSIDL_RESOURCES_LOCALIZED = &H39 ' Localized Resource Direcotry
CSIDL_COMMON_OEM_LINKS = &H3A ' Links to All Users OEM specific apps
CSIDL_CDBURN_AREA = &H3B ' USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning
CSIDL_COMPUTERSNEARME = &H3D ' Computers Near Me (computered from Workgroup membership)
End EnumPublic Enum CSIDL_FOLDERPATH
SHGFP_TYPE_CURRENT = &H0 ' Return the folder's current path.
SHGFP_TYPE_DEFAULT = &H1 ' Return the folder's default path.
End Enum1.对于Special Folder,比较容易。直接用Call SHGetSpecialFolderLocation(0, CSIDL, lPIDL)。
2.对于一般Folder,用ILCreateFromPathW。Private Declare Function ILCreateFromPathW Lib "shell32" (ByVal pwszPath As Long) As Long
#If WIN32_IE >= &H500 Then
Private Declare Sub ILFree Lib "shell32" (ByVal pidl As Long)
#Esle
Private Declare Sub ILFree Lib "shell32" Alias "#155" (ByVal pidl As Long)
#End IfPrivate Function PathToPIDL(ByVal sPath As String) As Long
Dim lRet As LonglRet = ILCreateFromPath(StrPtr(sPath))
If lRet = 0 Then
sPath = StrConv(sPath, VBUnicode)
lRet = ILCreateFromPath(sPath)
End IfPathToPIDL = lRet
End Function调用:
pidl = PathToPIDL(sPath)
ILFree pidl
pidl = 0不知我理解对不对。敬请参考。
CSIDL_DESKTOP = &H0 ' <desktop>
CSIDL_INTERNET = &H1 ' Internet Explorer (icon on desktop)
CSIDL_PROGRAMS = &H2 ' Start Menu\Programs
CSIDL_CONTROLS = &H3 ' My Computer\Control Panel
CSIDL_PRINTERS = &H4 ' My Computer\Printers
CSIDL_PERSONAL = &H5 ' My Documents
CSIDL_FAVORITES = &H6 ' <user name>\Favorites
CSIDL_STARTUP = &H7 ' Start Menu\Programs\Startup
CSIDL_RECENT = &H8 ' <user name>\Recent
CSIDL_SENDTO = &H9 ' <user name>\SendTo
CSIDL_BITBUCKET = &HA ' <desktop>\Recycle Bin
CSIDL_STARTMENU = &HB ' <user name>\Start Menu
CSIDL_MYDOCUMENTS = &HC ' logical "My Documents" desktop icon
CSIDL_MYMUSIC = &HD ' "My Music" folder
CSIDL_MYVIDEO = &HE ' "My Videos" folder
CSIDL_DESKTOPDIRECTORY = &H10 ' <user name>\Desktop
CSIDL_DRIVES = &H11 ' My Computer
CSIDL_NETWORK = &H12 ' Network Neighborhood (My Network Places)
CSIDL_NETHOOD = &H13 ' <user name>\nethood
CSIDL_FONTS = &H14 ' windows\fonts
CSIDL_TEMPLATES = &H15
CSIDL_COMMON_STARTMENU = &H16 ' All Users\Start Menu
CSIDL_COMMON_PROGRAMS = &H17 ' All Users\Start Menu\Programs
CSIDL_COMMON_STARTUP = &H18 ' All Users\Startup
CSIDL_COMMON_DESKTOPDIRECTORY = &H19 ' All Users\Desktop
CSIDL_APPDATA = &H1A ' <user name>\Application Data
CSIDL_PRINTHOOD = &H1B ' <user name>\PrintHood
CSIDL_LOCAL_APPDATA = &H1C ' <user name>\Local Settings\Applicaiton Data (non roaming)
CSIDL_ALTSTARTUP = &H1D ' non localized startup
CSIDL_COMMON_ALTSTARTUP = &H1E ' non localized common startup
CSIDL_COMMON_FAVORITES = &H1F
CSIDL_INTERNET_CACHE = &H20
CSIDL_COOKIES = &H21
CSIDL_HISTORY = &H22
CSIDL_COMMON_APPDATA = &H23 ' All Users\Application Data
CSIDL_WINDOWS = &H24 ' GetWindowsDirectory()
CSIDL_SYSTEM = &H25 ' GetSystemDirectory()
CSIDL_PROGRAM_FILES = &H26 ' C:\Program Files
CSIDL_MYPICTURES = &H27 ' C:\Program Files\My Pictures
CSIDL_PROFILE = &H28 ' USERPROFILE
CSIDL_SYSTEMX86 = &H29 ' x86 system directory on RISC
CSIDL_PROGRAM_FILESX86 = &H2A ' x86 C:\Program Files on RISC
CSIDL_PROGRAM_FILES_COMMON = &H2B ' C:\Program Files\Common
CSIDL_PROGRAM_FILES_COMMONX86 = &H2C ' x86 Program Files\Common on RISC
CSIDL_COMMON_TEMPLATES = &H2D ' All Users\Templates
CSIDL_COMMON_DOCUMENTS = &H2E ' All Users\Documents
CSIDL_COMMON_ADMINTOOLS = &H2F ' All Users\Start Menu\Programs\Administrative Tools
CSIDL_ADMINTOOLS = &H30 ' <user name>\Start Menu\Programs\Administrative Tools
CSIDL_CONNECTIONS = &H31 ' Network and Dial-up Connections
CSIDL_COMMON_MUSIC = &H35 ' All Users\My Music
CSIDL_COMMON_PICTURES = &H36 ' All Users\My Pictures
CSIDL_COMMON_VIDEO = &H37 ' All Users\My Video
CSIDL_RESOURCES = &H38 ' Resource Direcotry
CSIDL_RESOURCES_LOCALIZED = &H39 ' Localized Resource Direcotry
CSIDL_COMMON_OEM_LINKS = &H3A ' Links to All Users OEM specific apps
CSIDL_CDBURN_AREA = &H3B ' USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning
CSIDL_COMPUTERSNEARME = &H3D ' Computers Near Me (computered from Workgroup membership)
End EnumPublic Enum CSIDL_FOLDERPATH
SHGFP_TYPE_CURRENT = &H0 ' Return the folder's current path.
SHGFP_TYPE_DEFAULT = &H1 ' Return the folder's default path.
End Enum1.对于Special Folder,比较容易。直接用Call SHGetSpecialFolderLocation(0, CSIDL, lPIDL)。
2.对于一般Folder,用ILCreateFromPathW。Private Declare Function ILCreateFromPathW Lib "shell32" (ByVal pwszPath As Long) As Long
#If WIN32_IE >= &H500 Then
Private Declare Sub ILFree Lib "shell32" (ByVal pidl As Long)
#Esle
Private Declare Sub ILFree Lib "shell32" Alias "#155" (ByVal pidl As Long)
#End IfPrivate Function PathToPIDL(ByVal sPath As String) As Long
Dim lRet As LonglRet = ILCreateFromPath(StrPtr(sPath))
If lRet = 0 Then
sPath = StrConv(sPath, VBUnicode)
lRet = ILCreateFromPath(StrPtr(sPath)) 'StrPtr
End IfPathToPIDL = lRet
End Function调用:
pidl = PathToPIDL(sPath)
ILFree pidl
pidl = 0不知我理解对不对。敬请参考。