dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: Intermediate
Feb 10, 2001

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


GetFileIcon - Retrieve the icon associated to a file

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           '32x32 icon
    mbSmallIcon = SHGFI_SMALLICON           '16x16 icon
    mbShellSizeIcon = SHGFI_SHELLICONSIZE   'size used by the shell to display
End Enum                                    'the icons (for example 32x32 or 
                                            ' 48x48)

Public Enum mbIconTypeConstants
    mbNormalIcon = SHGFI_ICON               'normal icon
    mbSelectedIcon = SHGFI_SELECTED         'the icon when it is selected
    mbOpenIcon = SHGFI_OPENICON             'the icon used for open folders
End Enum

' Returns the description of the specified file/folder (for example "Folder",
' "Executable file", "Bmp Image" and so on)

' Get the file/folder's associated icon
'
' NOTE: uses the IconToPicture function
'       (you can find it elsewhere in the Code Bank)

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
    ' be sure that there is the mbNormalIcon too
    If mbIconType <> mbNormalIcon Then lIconType = lIconType Or mbNormalIcon
    ' retrieve the item's icon
    SHGetFileInfo sPath, 0, FInfo, Len(FInfo), lIconType
    ' convert the handle to a StdPicture
    Set GetFileIcon = IconToPicture(FInfo.hIcon)
End Function
Marco Bellinaso
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date