[SOLVED] Extracting icon of associated program

Post your Gambas programming questions here.
Post Reply
ForeverNoob
Posts: 11
Joined: Thursday 1st October 2020 10:11am

[SOLVED] Extracting icon of associated program

Post by ForeverNoob »

Hello,

How can my program find the icon associated with a specific mime-type?

TIA
Last edited by ForeverNoob on Sunday 15th September 2024 3:20pm, edited 1 time in total.
User avatar
BruceSteers
Posts: 1825
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Extracting icon of associated program

Post by BruceSteers »

Look at gb.desktop and DesktopMime.class https://gambaswiki.org/wiki/comp/gb.desktop/desktopmime

This will get the image from either a file name or from a mime type.
So you could use either...

hImage = GetMimeIcon("/path/to/the/file.html")
or
hImage = GetMimeIcon("text/html")


Public Sub GetMimeIcon(TypeOrFile As String, Optional Size As Integer = 32) As Image

  Dim hMime As DesktopMime 

  If Exists(TypeOrFile) Then ' if it's a file then get it's mimetype
    hMime = DesktopMime.FromFile(TypeOrFile)
  Else
    hMime = = DesktopMime[TypeOrFile]
  Endif

If not hMime Then Error.Raise("mime type not found for " & TypeOrFile)

  Dim hImage as Image = hMime.GetIcon(Size)
  Return hImage

End


Or try Desktop.GetFileIcon https://gambaswiki.org/wiki/comp/gb.des ... etfileicon
Dim hPic As Picture = Desktop.GetFileIcon(Path, iSize, True)


component gb.desktop must be added to project in project properties
If at first you don't succeed , try doing something differently.
BruceS
ForeverNoob
Posts: 11
Joined: Thursday 1st October 2020 10:11am

Re: Extracting icon of associated program

Post by ForeverNoob »

BruceSteers wrote: Sunday 15th September 2024 12:52pm
Dim hPic As Picture = Desktop.GetFileIcon(Path, iSize, True)

component gb.desktop must be added to project in project properties
That works fine. Thanks.
User avatar
BruceSteers
Posts: 1825
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: [SOLVED] Extracting icon of associated program

Post by BruceSteers »

you're welcome :)
If at first you don't succeed , try doing something differently.
BruceS
Post Reply