[SOLVED] Extracting icon of associated program

Post

Posted
Rating:
#1 (In Topic #1332)
Trainee
 Hello,

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

TIA
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
Look at gb.desktop and DesktopMime.class  /comp/gb.desktop/desktopmime - Gambas Documentation

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")

Code (gambas)

  1.  
  2. Public Sub GetMimeIcon(TypeOrFile As String, Optional Size As Integer = 32) As Image
  3.  
  4.   Dim hMime As DesktopMime
  5.  
  6.   If Exists(TypeOrFile) Then ' if it's a file then get it's mimetype
  7.     hMime = DesktopMime.FromFile(TypeOrFile)
  8.   Else
  9.     hMime = = DesktopMime[TypeOrFile]
  10.  
  11. If not hMime Then Error.Raise("mime type not found for " & TypeOrFile)
  12.  
  13.   Dim hImage as Image = hMime.GetIcon(Size)
  14.   Return hImage
  15.  
  16.  

Or try Desktop.GetFileIcon /comp/gb.desktop/desktop/getfileicon - Gambas Documentation

Code (gambas)

  1. Dim hPic As Picture = Desktop.GetFileIcon(Path, iSize, True)
  2.  

component gb.desktop must be added to project in project properties
Online now: No Back to the top

Post

Posted
Rating:
#3
Trainee

BruceSteers said

Code (gambas)

  1. Dim hPic As Picture = Desktop.GetFileIcon(Path, iSize, True)
  2.  
component gb.desktop must be added to project in project properties

That works fine. Thanks.
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
you're welcome :)
Online now: No Back to the top
1 guest and 0 members have just viewed this.