File Icon


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: File Icon

  1. #1
    c2i - Richard Clark Guest

    File Icon

    I post my question again (I did it first in VB7 newsgroup)
    Someone know how to retrieve the icon associated to a file by OS ?
    I didn't find any answers in System.IO Namespace.


    --
    Richard Clark - rc@c2i.fr
    ______________________________________________
    NOUVEAU : Liste de diffusion sur MS.NET
    Inscription en envoyant un mail :
    ----------------------------------------------
    dotnetfrance-subscribe@yahoogroups.com
    ----------------------------------------------
    http://www.c2i.fr - Le portail francophone
    Visual Basic,VB.NET,ASP, ASP.NET
    + de 517 aides disponibles (15/02)
    ______________________________________________



  2. #2
    Rob Teixeira Guest

    Re: File Icon


    It's really funny. I thought this would be covered by the framework. I didn't
    see any reason why this couldn't be a constructor to the Icon class or at
    least a method. In fact, that's where I started looking.
    Anyway, I can't find any piece of the framework that does this. Looks like
    you'll have to resort to the old-fashion approach: ExtractAssociatedIcon
    API call.
    Create a Form with a button and picturebox, then add the following code:

    Private Declare Ansi Function ExtractAsscociatedIcon Lib "shell32" _
    Alias "ExtractAssociatedIconA" (ByVal hInstance As Integer, _
    ByVal strFile As String, ByRef lpnIndex As Integer) As Integer


    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim FileIcon As System.Drawing.Icon
    Dim hIcon As Integer
    Dim nIndex As Integer

    nindex = 1
    hicon = ExtractAsscociatedIcon(0, "C:\autoexec.bat", nindex)

    If hicon <> 0 Then
    FileIcon = New System.Drawing.Icon(hicon)
    picturebox1.Image = FileIcon.ToBitmap()
    End If
    End Sub


    Note that creating an Icon object using this constructor (passing an existing
    icon handle) doesn't mean the Icon class will properly dispose the handle
    for you when you are done. You must clean up yourself using DeleteObject,
    though you should not have to worry about calling DestroyIcon.
    You could probably wrap this functionality up in a class that has a Dispose
    method.

    In the meantime, I would hope an MS person would help find out where this
    might be hiding in the Framework, or work on getting it in there.

    -Rob

    "c2i - Richard Clark" <rc@c2i.fr> wrote:
    >I post my question again (I did it first in VB7 newsgroup)
    >Someone know how to retrieve the icon associated to a file by OS ?
    >I didn't find any answers in System.IO Namespace.
    >
    >
    >--
    >Richard Clark - rc@c2i.fr
    >______________________________________________
    >NOUVEAU : Liste de diffusion sur MS.NET
    >Inscription en envoyant un mail :
    >----------------------------------------------
    > dotnetfrance-subscribe@yahoogroups.com
    >----------------------------------------------
    >http://www.c2i.fr - Le portail francophone
    >Visual Basic,VB.NET,ASP, ASP.NET
    >+ de 517 aides disponibles (15/02)
    >______________________________________________
    >
    >



  3. #3
    c2i - Richard Clark Guest

    Re: File Icon

    I've the same opinion than you. I have another method to extract icon but
    like you, it's the old-fashion.
    The only reason why this is not in the framework (but I'm sure I'm dreaming)
    it's to ensure the freamework will be other OS compatible ;-)


    --
    Richard Clark - rc@c2i.fr
    ______________________________________________
    NOUVEAU : Liste de diffusion sur MS.NET
    Inscription en envoyant un mail :
    ----------------------------------------------
    dotnetfrance-subscribe@yahoogroups.com
    ----------------------------------------------
    http://www.c2i.fr - Le portail francophone
    Visual Basic,VB.NET,ASP, ASP.NET
    + de 517 aides disponibles (15/02)
    ______________________________________________

    "Rob Teixeira" <RobTeixeira@@msn.com> wrote in message
    news:3a9ec2a1$1@news.devx.com...
    >
    > It's really funny. I thought this would be covered by the framework. I

    didn't
    > see any reason why this couldn't be a constructor to the Icon class or at
    > least a method. In fact, that's where I started looking.
    > Anyway, I can't find any piece of the framework that does this. Looks like
    > you'll have to resort to the old-fashion approach: ExtractAssociatedIcon
    > API call.
    > Create a Form with a button and picturebox, then add the following code:
    >
    > Private Declare Ansi Function ExtractAsscociatedIcon Lib "shell32" _
    > Alias "ExtractAssociatedIconA" (ByVal hInstance As Integer, _
    > ByVal strFile As String, ByRef lpnIndex As Integer) As Integer
    >
    >
    > Protected Sub Button1_Click(ByVal sender As Object, ByVal e As

    System.EventArgs)
    > Dim FileIcon As System.Drawing.Icon
    > Dim hIcon As Integer
    > Dim nIndex As Integer
    >
    > nindex = 1
    > hicon = ExtractAsscociatedIcon(0, "C:\autoexec.bat", nindex)
    >
    > If hicon <> 0 Then
    > FileIcon = New System.Drawing.Icon(hicon)
    > picturebox1.Image = FileIcon.ToBitmap()
    > End If
    > End Sub
    >
    >
    > Note that creating an Icon object using this constructor (passing an

    existing
    > icon handle) doesn't mean the Icon class will properly dispose the handle
    > for you when you are done. You must clean up yourself using DeleteObject,
    > though you should not have to worry about calling DestroyIcon.
    > You could probably wrap this functionality up in a class that has a

    Dispose
    > method.
    >
    > In the meantime, I would hope an MS person would help find out where this
    > might be hiding in the Framework, or work on getting it in there.
    >
    > -Rob
    >
    > "c2i - Richard Clark" <rc@c2i.fr> wrote:
    > >I post my question again (I did it first in VB7 newsgroup)
    > >Someone know how to retrieve the icon associated to a file by OS ?
    > >I didn't find any answers in System.IO Namespace.
    > >
    > >
    > >--
    > >Richard Clark - rc@c2i.fr
    > >______________________________________________
    > >NOUVEAU : Liste de diffusion sur MS.NET
    > >Inscription en envoyant un mail :
    > >----------------------------------------------
    > > dotnetfrance-subscribe@yahoogroups.com
    > >----------------------------------------------
    > >http://www.c2i.fr - Le portail francophone
    > >Visual Basic,VB.NET,ASP, ASP.NET
    > >+ de 517 aides disponibles (15/02)
    > >______________________________________________
    > >
    > >

    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center