Add associated file icon to listview
-
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