From 8f8e454b0d22ab31e250e0fca524557e59d00b81 Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Sun, 18 May 2014 19:54:52 -0400 Subject: [PATCH] Initial work on loading icon --- Common.csproj | 3 +++ Internet/Browser.cs | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/Common.csproj b/Common.csproj index 2fc6b1a..0e9399d 100644 --- a/Common.csproj +++ b/Common.csproj @@ -118,12 +118,14 @@ true + 3.5 + packages\Microsoft.Bcl.1.1.8\lib\net40\System.IO.dll @@ -136,6 +138,7 @@ packages\Microsoft.Bcl.1.1.8\lib\net40\System.Threading.Tasks.dll + diff --git a/Internet/Browser.cs b/Internet/Browser.cs index 598a79f..d77ebd2 100644 --- a/Internet/Browser.cs +++ b/Internet/Browser.cs @@ -2,15 +2,44 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Drawing; +using System.Runtime.InteropServices; +using System.Windows; +using System.Windows.Interop; +using System.Windows.Media; +using System.Windows.Media.Imaging; namespace Common.Internet { public class Browser { + [DllImport("shell32.dll", CharSet = CharSet.Auto)] + static extern uint ExtractIconEx(string szFileName, int nIconIndex, IntPtr[] phiconLarge, IntPtr[] phiconSmall, uint nIcons); + public string Key { get; private set; } public string Name { get; private set; } public string Command { get; private set; } public string DefaultIcon { get; private set; } + public ImageSource DefaultImage { get; private set; } + + public void LoadImage() + { + var parts = DefaultIcon.Split(','); + var index = int.Parse(parts[1]); + + var large = new IntPtr[1]; + var small = new IntPtr[1]; + ExtractIconEx(parts[0], index, large, small, 1); + + Icon img = Icon.FromHandle(small[0]); + + Bitmap bitmap = img.ToBitmap(); + IntPtr hBitmap = bitmap.GetHbitmap(); + + ImageSource wpfBitmap = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); + + DefaultImage = wpfBitmap; + } public bool SupportsPrivate() {