Voici un petit code qui permet d’obtenir l’icone d’une application et d’en faire un ImageSource exploitable via WPF. Rien de bien compliqué pour obtenir l’icone vu que l’on utilise System.Drawing, c’est surtout au niveau de l’Interop qu’il faut regarder ;)
Vb
Imports System Namespace WpfLib Public Class mlImage Public Shared Function ExtractAssociatedIcon(ByVal path As String) As System.Windows.Media.ImageSource Dim icon As System.Drawing.Icon = System.Drawing.Icon.ExtractAssociatedIcon(path) Return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon( _ icon.Handle, _ System.Windows.Int32Rect.Empty, _ System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()) End Function End Class End Namespace
C#
using System; namespace WpfLib { public static class mlImage { public static System.Windows.Media.ImageSource ExtractAssociatedIcon(String path) { System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(path); return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon( icon.Handle, System.Windows.Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); } } }