Solved

Get icon of file type

Posted on 2001-08-30
3
174 Views
Last Modified: 2010-08-05
how do i get the icon thats associated with an extension and add it to a listbox?
0
Comment
Question by:janus102700
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
BlaZer earned 300 total points
Comment Utility
Sub UpDateList()
Dim Item As ListItem
Dim CreatedTime As String
Dim ModifiedTime As String
ListView.ListItems.Clear
Set ListView.SmallIcons = Nothing
Dim CurrFIle As String
CurrFIle = Dir(M_Folder & "\", vbNormal)
While CurrFIle <> ""
Set Item = ListView.ListItems.Add()
Item.Key = M_Folder & "\" & CurrFIle
Item.Text = CurrFIle
Item.SubItems(1) = GetFileType("." & GetExtension(CurrFIle))
Item.SubItems(3) = FormatFileSize(FileLen(M_Folder & "\" & CurrFIle))
GetFileTimes M_Folder & "\" & CurrFIle, CreatedTime, ModifiedTime
Item.SubItems(4) = CreatedTime
Item.SubItems(5) = ModifiedTime
GetIcon Item.Key, Item.Index
CurrFIle = Dir
Wend
Set ListView.SmallIcons = Imagelist
For Each Item In ListView.ListItems
Item.SmallIcon = Item.Index
Next

End Sub
Private Function GetIcon(Filename As String, Index As Long) As Long
Dim hLIcon As Long, hSIcon As Long    'Large & Small Icons
Dim imgObj As ListImage               'Single bmp in imagelist.listimages collection
Dim r As Long

'Get a handle to the small icon
hSIcon = SHGetFileInfo(Filename, 0&, ShInfo, Len(ShInfo), _
         BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON)

If hSIcon <> 0 Then
  With Pic16
    Set .Picture = LoadPicture("")
    .AutoRedraw = True
    r = ImageList_Draw(hSIcon, ShInfo.iIcon, Pic16.hDC, 0, 0, ILD_TRANSPARENT)
    .Refresh
  End With
  Set imgObj = Imagelist.ListImages.Add(Index, , Pic16.Image)

End If

End Function

this will also show some  more data..but u can delete that!

0
 

Author Comment

by:janus102700
Comment Utility
umm....whats the  BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON

??

aint there something missing?
0
 
LVL 1

Expert Comment

by:BlaZer
Comment Utility
sorry

Private m_DataName
Private M_Folder
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

'Icon Sizes in pixels
Private Const LARGE_ICON As Integer = 32
Private Const SMALL_ICON As Integer = 16
Private Const MAX_PATH = 260

Private Const ILD_TRANSPARENT = &H1       'Display transparent

'ShellInfo Flags
Private Const SHGFI_DISPLAYNAME = &H200
Private Const SHGFI_EXETYPE = &H2000
Private Const SHGFI_SYSICONINDEX = &H4000 'System icon index
Private Const SHGFI_LARGEICON = &H0       'Large icon
Private Const SHGFI_SMALLICON = &H1       'Small icon
Private Const SHGFI_SHELLICONSIZE = &H4
Private Const SHGFI_TYPENAME = &H400

Private Const BASIC_SHGFI_FLAGS = SHGFI_TYPENAME _
        Or SHGFI_SHELLICONSIZE Or SHGFI_SYSICONINDEX _
        Or SHGFI_DISPLAYNAME Or SHGFI_EXETYPE

Private Type SHFILEINFO                   'As required by ShInfo
  hIcon As Long
  iIcon As Long
  dwAttributes As Long
  szDisplayName As String * MAX_PATH
  szTypeName As String * 80
End Type


'----------------------------------------------------------
'Functions & Procedures
'----------------------------------------------------------
Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" _
    (ByVal pszPath As String, _
    ByVal dwFileAttributes As Long, _
    psfi As SHFILEINFO, _
    ByVal cbSizeFileInfo As Long, _
    ByVal uFlags As Long) As Long

Private Declare Function ImageList_Draw Lib "comctl32.dll" _
    (ByVal himl&, ByVal i&, ByVal hDCDest&, _
    ByVal X&, ByVal Y&, ByVal flags&) As Long


'----------------------------------------------------------
'Private variables
'----------------------------------------------------------
Private ShInfo As SHFILEINFO
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now