mirror of https://github.com/dahall/Vanara.git
Added extension assembly for WPF
parent
c3078b052b
commit
a7669dd9b3
22
Vanara.sln
22
Vanara.sln
|
@ -348,7 +348,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vanara.Windows.Shell.Common
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vanara.Windows.Extensions", "Windows.Extensions\Vanara.Windows.Extensions.csproj", "{AE4636A6-A15A-4A73-8F7D-D5F878276992}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vanara.WinUI.Extensions", "WinUI.Extensions\Vanara.WinUI.Extensions.csproj", "{52F98DFA-8430-4BA7-9937-D0087D17B56E}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vanara.WinUI.Extensions", "WinUI.Extensions\Vanara.WinUI.Extensions.csproj", "{52F98DFA-8430-4BA7-9937-D0087D17B56E}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vanara.WPF.Extensions", "WPF.Extensions\Vanara.WPF.Extensions.csproj", "{499D0D5C-31BF-48E9-B20C-3B854C56A90B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -2155,6 +2157,24 @@ Global
|
|||
{52F98DFA-8430-4BA7-9937-D0087D17B56E}.Release|x64.Build.0 = Release|Any CPU
|
||||
{52F98DFA-8430-4BA7-9937-D0087D17B56E}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{52F98DFA-8430-4BA7-9937-D0087D17B56E}.Release|x86.Build.0 = Release|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.DebugNoTests|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.DebugNoTests|Any CPU.Build.0 = Debug|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.DebugNoTests|x64.ActiveCfg = Debug|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.DebugNoTests|x64.Build.0 = Debug|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.DebugNoTests|x86.ActiveCfg = Debug|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.DebugNoTests|x86.Build.0 = Debug|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.Release|x64.Build.0 = Release|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{499D0D5C-31BF-48E9-B20C-3B854C56A90B}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
using System.Windows.Media.Imaging;
|
||||
using static System.Windows.Interop.Imaging;
|
||||
using static Vanara.PInvoke.Gdi32;
|
||||
using static Vanara.PInvoke.User32;
|
||||
|
||||
namespace Vanara.PInvoke
|
||||
{
|
||||
/// <summary>Extension methods to convert GdiObj handle variants to their .NET equivalents.</summary>
|
||||
public static class GdiObjExtensions2
|
||||
{
|
||||
/// <summary>Creates a <see cref="BitmapSource"/> from an <see cref="SafeHBITMAP"/> preserving transparency, if possible.</summary>
|
||||
/// <param name="hbmp">The SafeHBITMAP value.</param>
|
||||
/// <returns>The BitmapSource instance. If <paramref name="hbmp"/> is a <c>NULL</c> handle, <see langword="null"/> is returned.</returns>
|
||||
public static BitmapSource ToBitmapSource(this SafeHBITMAP hbmp) => hbmp is null || hbmp.IsInvalid ? null : CreateBitmapSourceFromHBitmap(hbmp.DangerousGetHandle(), default, default, BitmapSizeOptions.FromEmptyOptions());
|
||||
|
||||
/// <summary>Creates a <see cref="BitmapSource"/> from an <see cref="HBITMAP"/> preserving transparency, if possible.</summary>
|
||||
/// <param name="hbmp">The HBITMAP value.</param>
|
||||
/// <returns>The BitmapSource instance. If <paramref name="hbmp"/> is a <c>NULL</c> handle, <see langword="null"/> is returned.</returns>
|
||||
public static BitmapSource ToBitmapSource(this in HBITMAP hbmp) => hbmp.IsNull ? null : CreateBitmapSourceFromHBitmap(hbmp.DangerousGetHandle(), default, default, BitmapSizeOptions.FromEmptyOptions());
|
||||
|
||||
/// <summary>Creates a managed <see cref="BitmapSource"/> from a HICON instance.</summary>
|
||||
/// <returns>A managed bitmap instance.</returns>
|
||||
public static BitmapSource ToBitmapSource(this in HICON hIcon) => hIcon.IsNull ? null : CreateBitmapSourceFromHIcon(hIcon.DangerousGetHandle(), default, BitmapSizeOptions.FromEmptyOptions());
|
||||
|
||||
/// <summary>Creates a managed <see cref="BitmapSource"/> from a SafeHICON instance.</summary>
|
||||
/// <returns>A managed bitmap instance.</returns>
|
||||
public static BitmapSource ToBitmapSource(this SafeHICON hIcon) => hIcon is null || hIcon.IsInvalid ? null : CreateBitmapSourceFromHIcon(hIcon.DangerousGetHandle(), default, BitmapSizeOptions.FromEmptyOptions());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Vanara.PInvoke
|
||||
{
|
||||
/// <summary>Conversion extension methods for WinUI/UWP and Vanara types.</summary>
|
||||
public static class SystemWindowsExtensions
|
||||
{
|
||||
/// <summary>Converts <see cref="COLORREF"/> to <see cref="Color"/>.</summary>
|
||||
/// <param name="c">The color to convert.</param>
|
||||
/// <returns>The converted value.</returns>
|
||||
public static Color ToColor(this in COLORREF c) => new() { A = c.A, R = c.R, G = c.G, B = c.B };
|
||||
|
||||
/// <summary>Converts <see cref="Color"/> to <see cref="COLORREF"/>.</summary>
|
||||
/// <param name="c">The color to convert.</param>
|
||||
/// <returns>The converted value.</returns>
|
||||
public static COLORREF ToCOLORREF(this in Color c) => new(c.R, c.G, c.B) { A = c.A };
|
||||
|
||||
/// <summary>Converts <see cref="POINT"/> to <see cref="Point"/>.</summary>
|
||||
/// <param name="pt">The point to convert.</param>
|
||||
/// <returns>The converted value.</returns>
|
||||
public static Point ToPoint(this in POINT pt) => new(pt.X, pt.Y);
|
||||
|
||||
/// <summary>Converts <see cref="RECT"/> to <see cref="Int32Rect"/>.</summary>
|
||||
/// <param name="r">The rectangle to convert.</param>
|
||||
/// <returns>The converted value.</returns>
|
||||
public static Int32Rect ToRect(this in RECT r) => new(r.X, r.Y, r.Width, r.Height);
|
||||
|
||||
/// <summary>Converts <see cref="RECT"/> to <see cref="Int32Rect"/>.</summary>
|
||||
/// <param name="r">The rectangle to convert.</param>
|
||||
/// <returns>The converted value.</returns>
|
||||
public static RECT ToRECT(this in Int32Rect r) => new(r.X, r.Y, r.X + r.Width, r.Y + r.Height);
|
||||
|
||||
/// <summary>Converts <see cref="SIZE"/> to <see cref="Size"/>.</summary>
|
||||
/// <param name="sz">The size to convert.</param>
|
||||
/// <returns>The converted value.</returns>
|
||||
public static Size ToSize(this in SIZE sz) => new(sz.cx, sz.cy);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Description>Extension methods and conversions from Vanara P/Invoke types and methods to WPF types and methods.</Description>
|
||||
<AssemblyTitle>$(AssemblyName)</AssemblyTitle>
|
||||
<TargetFrameworks>net35;net40;net45;net5.0-windows;net6.0-windows;netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
|
||||
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
|
||||
<UseWPF>true</UseWPF>
|
||||
<DefineConstants>$(DefineConstants);WPF</DefineConstants>
|
||||
<AssemblyName>Vanara.WPF.Extensions</AssemblyName>
|
||||
<PackageId>$(AssemblyName)</PackageId>
|
||||
<PackageTags>pinvoke;vanara;net-extensions;interop;extensions;wpf</PackageTags>
|
||||
<PackageReleaseNotes>Currently implements:
|
||||
|
||||
Classes
|
||||
GdiExtension, GdiObjExtensions2, SafeTempHDC, SmartBitmapLock
|
||||
|
||||
Enumerations
|
||||
Corners
|
||||
|
||||
</PackageReleaseNotes>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PInvoke\Gdi32\Vanara.PInvoke.Gdi32.csproj" />
|
||||
<ProjectReference Include="..\PInvoke\User32\Vanara.PInvoke.User32.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" $(TargetFramework.StartsWith('netcore2')) Or $(TargetFramework.StartsWith('net2')) Or $(TargetFramework.StartsWith('net3')) Or $(TargetFramework.StartsWith('net4')) ">
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue