Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Add associated file icon to listview

Add associated file icon to listview

Scheduled Pinned Locked Moved Visual Basic
databasejsonquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shinay
    wrote on last edited by
    #1

    I am trying to add the asscociated file icon in the listview( lvwFileNodeList ). I successfully add the icon for the first found file, but for the rest it uses the same icon to display the associated icon. As the following, i am adding the file icon in the image list with the extension as a key and add this icon when adding this file to the list view. there must be the extra step i have to do does any know what 'm missing? my envrionment is vb6/xp pro Me.ImageList2.ListImages.Add , FindExtension(strFileName), GetIcon(strFilePath, SHGFI_SMALLICON) Set objListItem = Me.lvwFileNodeList.ListItems.Add objListItem.SubItems(3) = strFilePath objListItem.SmallIcon = FindExtension(strFileName) Public Function GetIcon(filename As String, icon_size As Long) As IPictureDisp Dim index As Integer Dim hIcon As Long Dim item_num As Long Dim icon_pic As IPictureDisp Dim sh_info As SHFILEINFO SHGetFileInfo filename, 0, sh_info, _ Len(sh_info), SHGFI_ICON + icon_size hIcon = sh_info.hIcon Set icon_pic = IconToPicture(hIcon) Set GetIcon = icon_pic 'GetIcon = sh_info.hIcon End Function ' Convert an icon handle into an IPictureDisp. Private Function IconToPicture(hIcon As Long) As IPictureDisp Dim cls_id As CLSID Dim hRes As Long Dim new_icon As TypeIcon Dim lpUnk As IUnknown With new_icon .cbSize = Len(new_icon) .picType = vbPicTypeIcon .hIcon = hIcon End With With cls_id .id(8) = &HC0 .id(15) = &H46 End With hRes = OleCreatePictureIndirect(new_icon, _ cls_id, 1, lpUnk) If hRes = 0 Then Set IconToPicture = lpUnk End Function

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups