CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2000
    Location
    St. Paul, Minnesota
    Posts
    49

    display icon associated with program

    Is there a way to make a treeview control show the icon that is associated with a file without loading all the pictures in a imagelist? Maybe by using explorer?


  2. #2
    Join Date
    Mar 2001
    Location
    Canada
    Posts
    13

    Re: display icon associated with program

    I think you don't have to load all pictures in a imagelist. You can use ListImages.Add method:


    ...
    imgList.ListImages.Add , "File1", picPicture.Picture
    lstBrowser.ListItems.Add , , "File Name", "File1"
    ...




    Another question is how to get those icons associated with files. By using the Registry? Any ideas?

    Next question!

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: display icon associated with program

    I have not tried -and I cannot, by now - but if I 'd to display iconns from file, I would give a look at ExtractIcon inside Vb...

    Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: display icon associated with program

    Like this?


    private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (byval hInst as Long, byval lpszExeFileName as string, byval nIconIndex as Long) as Long


    '\\ --[IconsFromFilename]-------------------------------------------------------------------
    '\\ Returns a collection of ApiIcon objects from the filename given.
    '\\ ----------------------------------------------------------------------------------------
    '\\ You have a royalty free right to use, reproduce, modify, publish and mess with this code
    '\\ I'd like you to visit http://www.merrioncomputing.com for updates, but won't force you
    '\\ ----------------------------------------------------------------------------------------
    public Function IconsFromExeFilename(byval Filename as string) as Collection

    Dim lIndex as Long
    Dim lIconCount as Long
    Dim lRet as Long

    Dim colIcons as Collection
    Dim sExeString as string
    Dim thisIcon as Long

    '\\ Initialise the collection
    set colIcons = new Collection

    '\\ get the number of items
    lIconCount = ExtractIcon(App.hInstance, Filename, -1)
    If lIconCount > 0 then
    for lIndex = 0 to lIconCount - 1
    lRet = ExtractIcon(App.hInstance, Filename, lIndex)
    If lRet > 0 then
    thisIcon = lRet
    colIcons.Add thisIcon
    End If
    next lIndex
    End If

    '\\ Return the collection
    set IconsFromExeFilename = colIcons

    End Function




    HTH,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

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

Featured