Results 1 to 2 of 2

Thread: retrieving icons of a file type

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 1999
    Posts
    56
    I'm using a ListView in my program and I was wondering if it is possible to use the icon associated with a certain file type on the user's system. Right now, I can only use my own preset icons in an imagelist, but I want to be able to use the icons on the user's system. Is this possible? Thanks in advance.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    This part will extra your icons from a file
    Code:
    Declare Function ExtractIconEx Lib "shell32" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Long, phIconLarge As Long, phIconSmall As Long, ByVal nIcons As Long) As Long
    
    Function GetIconsFromFile(Filename$)
        Dim hIcons()
        ReDim hIcons(ExtractIconEx(Filename, -1, ByVal 0&, ByVal 0&, 0))
        If UBound(hIcons) = 0 Then Exit Function Else ReDim Preserve hIcons(UBound(hIcons) - 1)
        ExtractIconEx Filename, 0, hIcons(0), ByVal 0&, 10
        GetIconsFromFile = hIcons
    End Function
    In registry you've got the key ie ".bas"
    HKEY_CLASSES_ROOT\.bas\
    which default property "VisualBasic.Module" point you to:
    HKEY_CLASSES_ROOT\VisualBasic.Module\DefaultIcon
    which default property is:
    D:\program files\vb5\vb5.exe,8
    declare an long array and assign it GetIconsFromFile and the 8'th icon is your handle
    draw it on a device context with drawicon api
    Code:
    Declare Function DrawIcon Lib "user32" Alias "DrawIcon" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width