'Filename : Get File Icon.cls (cFileIcon Class Module)
'Description : Get icon(s) of an existing file
'Date : Tuesday, January 07, 2003, 10:12 AM
'Last Update : Friday, November 25, 2005, 12:28 AM
'You can freely use and distribute this class or upload these codes on any site
'provided that the original credits are kept unmodified.
'Keep note that :
'If File property is not set, the current directory will automatically be used by API.
'Credits goes to:
'Makers of the great Win32 Programmer's Reference, don't know who you are but thanks.
'Christoph von Wittich (Christoph@ActiveVB.de), author of ApiViewer 2004 for the APIs
'Modified API Declaration
Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long, ByRef psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As ESHGetFileInfoFlagConstants) As Long
Private Declare Sub OleCreatePictureIndirect Lib "oleaut32.dll" (ByRef lpPictDesc As PictDesc, ByRef riid As Guid, ByVal fOwn As Long, ByRef lplpvObj As IPictureDisp)
'API Constants
Private Const ERRORAPI As Long = 0
Private Const MAX_PATH As Long = 260
'API Types
Private Type Guid
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Type PictDesc
cbSizeofStruct As Long
picType As Long
hImage As Long
xExt As Long
yExt As Long
End Type
Private Type SHFILEINFO
hIcon As Long ' : icon
iIcon As Long ' : icondex
dwAttributes As Long ' : SFGAO_ flags
szDisplayName As String * MAX_PATH ' : display name (or path)
szTypeName As String * 80 ' : type name
End Type
'User-Defined API Enum
Private Enum ESHGetFileInfoFlagConstants
SHGFI_ATTRIBUTES = &H800 'get file attributes
SHGFI_DISPLAYNAME = &H200 'get display name
SHGFI_EXETYPE = &H2000 'get exe type
SHGFI_ICON = &H100 'get icon handle and index
SHGFI_LARGEICON = &H0 'get file's large icon
SHGFI_LINKOVERLAY = &H8000 'add link overlay on the icon
SHGFI_OPENICON = &H2 'get file's open icon
SHGFI_SELECTED = &H10000 'blend icon with the system highlight color
SHGFI_SHELLICONSIZE = &H4 'get shell-sized icon
SHGFI_SMALLICON = &H1 'get file's small icon
SHGFI_SYSICONINDEX = &H4000 'get icon index from system image list