Private Const MAX_PATH = 260
Private Type SHFILEINFO hIcon As Long iIcon As Long dwAttributes As Long szDisplayName As String * MAX_PATH szTypeName As String * 80 End Type
Private Declare Function SHGetFileInfo Lib "Shell32" Alias "SHGetFileInfoA" _ (ByVal pszPath As Any, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, _ ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long
Private Const SHGFI_ICON = &H100 Private Const SHGFI_OPENICON = &H2 Private Const SHGFI_SELECTED = &H10000
Private Const SHGFI_SHELLICONSIZE = &H4 Private Const SHGFI_SMALLICON = &H1 Private Const SHGFI_LARGEICON = &H0
Public Enum mbIconSizeConstants mbLargeIcon = SHGFI_LARGEICON mbSmallIcon = SHGFI_SMALLICON mbShellSizeIcon = SHGFI_SHELLICONSIZE End Enum
Public Enum mbIconTypeConstants mbNormalIcon = SHGFI_ICON mbSelectedIcon = SHGFI_SELECTED mbOpenIcon = SHGFI_OPENICON End Enum
Function GetFileIcon(ByVal sPath As String, Optional ByVal mbIconSize As _ mbIconSizeConstants = mbLargeIcon, Optional ByVal mbIconType As _ mbIconTypeConstants = mbNormalIcon) As StdPicture Dim FInfo As SHFILEINFO Dim lIconType As Long lIconType = mbIconSize Or mbIconType If mbIconType <> mbNormalIcon Then lIconType = lIconType Or mbNormalIcon SHGetFileInfo sPath, 0, FInfo, Len(FInfo), lIconType Set GetFileIcon = IconToPicture(FInfo.hIcon) End Function |