Solved

Get icon of file type

Posted on 2001-08-30
3
176 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
ID: 6441966
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
ID: 6441973
umm....whats the  BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON

??

aint there something missing?
0
 
LVL 1

Expert Comment

by:BlaZer
ID: 6441976
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBS file using code from 2nd file (txt or vbs) 4 36
How to debug this code 7 61
Microsoft Access combo box help 2 45
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 46
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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