Results 1 to 9 of 9

Thread: Adding icons to listview at runtime...?

  1. #1

    Thread Starter
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828

    Question Adding icons to listview at runtime...?

    Ok i've done a search and found not much

    also none of it was all that helpful...

    how can i do this simplish task???

    i know how to extract icons from files (any file) to a picture box but when i try and add it to the imagelist it doesn't work

    any suggestions, or has anyone done this before ?
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  2. #2
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Add a picture to ImageList using ListImages collection and then use its key when adding item to the listview or using its icon properties..

  3. #3

    Thread Starter
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    yes but how do i add it to the imagelist???

    i cant use LoadPicture can i...
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  4. #4

    Thread Starter
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    anyone?
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  5. #5
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Hope this will help..
    First set the ImageLists for smallicons, largeicons at designtime..
    VB Code:
    1. Private Sub Command1_Click()
    2. ImageList1.ListImages.Add , "pic1", LoadPicture("c:\windows\clouds.bmp")
    3.  
    4. ListView1.ListItems.Add , "sdf", "There", "pic1", "pic1"
    5.  
    6. End Sub

  6. #6

    Thread Starter
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    nope, not at all
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  7. #7
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    This sub comes from an app of mine which lists all items on the desktop in a listview and adds their icons.
    It uses a function with Dir() to loop through the desktop, which isn't added here.

    Hopes it helps. I don't have more time to specify it for your problem so I just post the entire sub:

    VB Code:
    1. Public Sub DisplayIcons(Filename As String)
    2.     Dim fname As String
    3.     fname = Filename
    4.     Dim hImgSmall As Long
    5.     Dim hImgLarge As Long
    6.     Dim info1 As String
    7.     Dim info2 As String
    8.     On Local Error GoTo cmdLoadErrorHandler
    9.  
    10.         hImgSmall = SHGetFileInfo(fname$, 0&, shinfo, Len(shinfo), BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON)
    11.         info1 = Left$(shinfo.szDisplayName, InStr(shinfo.szDisplayName, Chr$(0)) - 1)
    12.         info2 = Left$(shinfo.szTypeName, InStr(shinfo.szTypeName, Chr$(0)) - 1)
    13.         PicSmall.Picture = LoadPicture()
    14.         PicSmall.AutoRedraw = True
    15.         ImageList_Draw hImgSmall&, shinfo.iIcon, PicSmall.hDC, 0, 0, ILD_TRANSPARENT
    16.         PicSmall.Picture = PicSmall.Image
    17.         imlSmall.ListImages.Add ItemCount, , PicSmall.Picture
    18.         hImgLarge = SHGetFileInfo(fname, 0&, shinfo, Len(shinfo), BASIC_SHGFI_FLAGS Or SHGFI_LARGEICON)
    19.         info1 = Left$(shinfo.szDisplayName, InStr(shinfo.szDisplayName, Chr$(0)) - 1)
    20.         info2 = Left$(shinfo.szTypeName, InStr(shinfo.szTypeName, Chr$(0)) - 1)
    21.         PicLarge.Picture = LoadPicture()
    22.         PicLarge.AutoRedraw = True
    23.         ImageList_Draw hImgLarge&, shinfo.iIcon, PicLarge.hDC, 0, 0, ILD_TRANSPARENT
    24.         PicLarge.Picture = PicLarge.Image
    25.         imlLarge.ListImages.Add ItemCount, , PicLarge.Picture
    26.         Exit Sub
    27.        
    28. cmdLoadErrorHandler:
    29.   pixLarge.Picture = LoadPicture()
    30.  
    31. End Sub

  8. #8
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    Oops.

    Here is some API stuff that you'll probably need

    VB Code:
    1. Public Const MAX_PATH = 260
    2.    Public Const SHGFI_DISPLAYNAME = &H200
    3.    Public Const SHGFI_EXETYPE = &H2000
    4.    Public Const SHGFI_SYSICONINDEX = &H4000 'system icon index
    5.    Public Const SHGFI_LARGEICON = &H0 'large icon
    6.    Public Const SHGFI_SMALLICON = &H1 'small icon
    7.    Public Const ILD_TRANSPARENT = &H1 'display transparent
    8.    Public Const SHGFI_SHELLICONSIZE = &H4
    9.    Public Const SHGFI_TYPENAME = &H400
    10.    Public Const BASIC_SHGFI_FLAGS = SHGFI_TYPENAME _
    11.    Or SHGFI_SHELLICONSIZE Or SHGFI_SYSICONINDEX _
    12.    Or SHGFI_DISPLAYNAME Or SHGFI_EXETYPE
    13.  
    14.  
    15.    Public Type SHFILEINFO
    16.        hIcon As Long
    17.        iIcon As Long
    18.        dwAttributes As Long
    19.        szDisplayName As String * MAX_PATH
    20.        szTypeName As String * 80
    21.        End Type
    22.  
    23.  
    24.    Public Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" _
    25.        (ByVal pszPath As String, _
    26.        ByVal dwFileAttributes As Long, _
    27.        psfi As SHFILEINFO, _
    28.        ByVal cbSizeFileInfo As Long, _
    29.        ByVal uFlags As Long) As Long
    30.  
    31.  
    32.    Public Declare Function ImageList_Draw Lib "comctl32.dll" _
    33.        (ByVal himl&, ByVal i&, ByVal hDCDest&, _
    34.        ByVal x&, ByVal y&, ByVal flags&) As Long
    35.        Public shinfo As SHFILEINFO

  9. #9
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    It uses 2 pictureboxes and 2 imagelists.

    I use it like this:

    VB Code:
    1. DisplayIcons LoadFiles '=filename
    2.  
    3. ListView1.ListItems.Add ItemCount, , LoadFiles, ItemCount, ItemCount

    I've got to go now. If you have more questions about it:
    I'll be back!

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