From ce28b45d485777330a9f5fafdd1b412e6667959d Mon Sep 17 00:00:00 2001 From: David Hall Date: Sun, 9 Jun 2024 16:07:36 -0600 Subject: [PATCH] WIP on ShellItemSource --- WinUI.Extensions/ShellImageSource.cs | 52 +++++++++++++++++++++++++ WinUI.Extensions/Vanara.WinUI.Extensions.csproj | 1 + 2 files changed, 53 insertions(+) create mode 100644 WinUI.Extensions/ShellImageSource.cs diff --git a/WinUI.Extensions/ShellImageSource.cs b/WinUI.Extensions/ShellImageSource.cs new file mode 100644 index 00000000..12987e3e --- /dev/null +++ b/WinUI.Extensions/ShellImageSource.cs @@ -0,0 +1,52 @@ +using System.Drawing; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media; +using Vanara.Windows.Shell; +using static Vanara.PInvoke.User32; +using static Vanara.PInvoke.Shell32; +using static Vanara.PInvoke.Shell32.ShellUtil; +using System.IO; +using System.Windows.Media.Imaging; + +namespace Vanara.PInvoke; + +/*internal class ShellImageSource : BitmapSource +{ + public ShellImageSource(string path, System.Drawing.Size imageSize) + { + SHCreateItemFromParsingName(path, null, typeof(IShellItemImageFactory).GUID, out var ppv).ThrowIfFailed(); + ((IShellItemImageFactory)ppv!).GetImage(imageSize, SIIGBF.SIIGBF_INCACHEONLY, out var hbmp).ThrowIfFailed(); + + if (LoadImageFromImageFactory(path, ref imageSize, SIIGBF.SIIGBF_INCACHEONLY, out var hbmp).Succeeded && hbmp != null) + if (cache.TryGetValue(path, out var bmp)) + Bitmap = bmp; + bool? isDir = IsDirFile(path); + + + var hico = ShellImageList.GetFileIcon(path, iconType) ?? ShellImageList.GetSystemIcon(path, iconType); + } + + private static IShellItemImageFactory GetFactory(string path) + { + SHCreateItemFromParsingName(path, null, typeof(IShellItemImageFactory).GUID, out var ppv).ThrowIfFailed(); + return (IShellItemImageFactory)ppv!; + } + + private static IShellItemImageFactory GetFactory(PIDL pidl) + { + SHCreateItemFromIDList(pidl, typeof(IShellItemImageFactory).GUID, out var ppv).ThrowIfFailed(); + return (IShellItemImageFactory)ppv!; + } + + private static async Task GetImageAsync(IShellItemImageFactory siif, System.Drawing.Size imageSize) + { + siif.GetImage(imageSize, SIIGBF.SIIGBF_INCACHEONLY, out var hbmp).ThrowIfFailed(); + + } + + protected override Freezable CreateInstanceCore() => throw new NotImplementedException(); +}*/ \ No newline at end of file diff --git a/WinUI.Extensions/Vanara.WinUI.Extensions.csproj b/WinUI.Extensions/Vanara.WinUI.Extensions.csproj index 2c651fb4..93a0ccf7 100644 --- a/WinUI.Extensions/Vanara.WinUI.Extensions.csproj +++ b/WinUI.Extensions/Vanara.WinUI.Extensions.csproj @@ -23,6 +23,7 @@ SystemFoundationExtensions +