Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

GetFileIcon - Retrieve the icon associated to a file

Total Hit ( 5045)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 



Click here to copy the following block
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


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.