init
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using Microsoft.Windows.Sdk;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace NotificationFlyout.Wpf.UI.Extensions
|
||||
{
|
||||
public static class ImageSourceExtensions
|
||||
{
|
||||
public static Icon ConvertToIcon(this ImageSource imageSource, uint dpi)
|
||||
{
|
||||
if (imageSource == null) return null;
|
||||
|
||||
var uri = new Uri(imageSource.ToString(), UriKind.RelativeOrAbsolute);
|
||||
|
||||
var streamResource = Application.GetResourceStream(uri);
|
||||
if (streamResource == null) throw new ArgumentException(nameof(streamResource));
|
||||
|
||||
return new Icon(streamResource.Stream, new System.Drawing.Size(PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CXICON, dpi), PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CYICON, dpi)));
|
||||
}
|
||||
|
||||
private enum SystemMetricFlag : int
|
||||
{
|
||||
SM_CXICON = 11,
|
||||
SM_CYICON = 12,
|
||||
SM_CXSMICON = 49,
|
||||
SM_CYSMICON = 50
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using NotificationFlyout.Wpf.UI.Helpers;
|
||||
using System;
|
||||
|
||||
namespace NotificationFlyout.Wpf.UI.Extensions
|
||||
{
|
||||
public static class OperatingSystemExtensions
|
||||
{
|
||||
public static bool IsGreaterThan(this OperatingSystem operatingSystem, OperatingSystemVersion version)
|
||||
{
|
||||
return operatingSystem.Version.Build > (int)version;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace NotificationFlyout.Wpf.UI.Helpers
|
||||
{
|
||||
public enum OperatingSystemVersion : int
|
||||
{
|
||||
Windows10 = 10240,
|
||||
Windows10_1511 = 10586,
|
||||
Windows10_1607 = 14393,
|
||||
Windows10_1703 = 15063,
|
||||
Windows10_1709 = 16299,
|
||||
Windows10_1803 = 17134,
|
||||
Windows10_1809 = 17763,
|
||||
Windows10_1903 = 18362
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Microsoft.Windows.Sdk;
|
||||
using System.Windows;
|
||||
|
||||
namespace NotificationFlyout.Wpf.UI.Extensions
|
||||
{
|
||||
internal static class RECTExtensions
|
||||
{
|
||||
internal static Rect ToRect(this RECT rect)
|
||||
{
|
||||
if (rect.right - rect.left < 0 || rect.bottom - rect.top < 0) return new Rect(rect.left, rect.top, 0, 0);
|
||||
|
||||
return new Rect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace NotificationFlyout.Wpf.UI.Extensions
|
||||
{
|
||||
public static class RegistryKeyExtensions
|
||||
{
|
||||
public static T GetValue<T>(this RegistryKey self, string valueName, T defaultValue)
|
||||
{
|
||||
return self.GetValue(valueName, defaultValue) is T t ? t : defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace NotificationFlyout.Wpf.UI.Extensions
|
||||
{
|
||||
public static class VisualExtensions
|
||||
{
|
||||
private static Matrix GetDpi(this Visual visual)
|
||||
{
|
||||
var source = PresentationSource.FromVisual(visual);
|
||||
if (source?.CompositionTarget != null) return (Matrix)source?.CompositionTarget.TransformToDevice;
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
public static double DpiY(this Visual visual)
|
||||
{
|
||||
return GetDpi(visual).M22;
|
||||
}
|
||||
|
||||
public static double DpiX(this Visual visual)
|
||||
{
|
||||
return GetDpi(visual).M11;
|
||||
}
|
||||
|
||||
public static bool TryGetTransformToDevice(this Visual visual, out Matrix value)
|
||||
{
|
||||
var presentationSource = PresentationSource.FromVisual(visual);
|
||||
if (presentationSource != null)
|
||||
{
|
||||
value = presentationSource.CompositionTarget.TransformToDevice;
|
||||
return true;
|
||||
}
|
||||
|
||||
value = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using Microsoft.Windows.Sdk;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
|
||||
namespace NotificationFlyout.Wpf.UI.Extensions
|
||||
{
|
||||
public static class WindowExtensions
|
||||
{
|
||||
[Flags]
|
||||
private enum WindowFlag : uint
|
||||
{
|
||||
SWP_NOSIZE = 0x0001,
|
||||
SWP_NOMOVE = 0x0002,
|
||||
SWP_NOZORDER = 0x0004,
|
||||
SWP_NOACTIVATE = 0x0010,
|
||||
WS_EX_NOACTIVATE = 0x08000000,
|
||||
SWP_SHOWWINDOW = 0x0040
|
||||
}
|
||||
|
||||
public static void SetWindowPosition(this Window window, double top, double left, double height, double width)
|
||||
{
|
||||
PInvoke.SetWindowPos((HWND)window.GetHandle(), (HWND)IntPtr.Zero, (int)left, (int)top, (int)width, (int)height, (uint)WindowFlag.SWP_NOSIZE | (uint)WindowFlag.SWP_NOZORDER | (uint)WindowFlag.SWP_NOACTIVATE);
|
||||
}
|
||||
|
||||
public static void SetTopAll(this Window window)
|
||||
{
|
||||
PInvoke.SetWindowPos((HWND)window.GetHandle(), (HWND)new IntPtr(-1), 0, 0, 0, 0, (uint)WindowFlag.SWP_NOMOVE | (uint)WindowFlag.SWP_NOSIZE | (uint)WindowFlag.WS_EX_NOACTIVATE);
|
||||
}
|
||||
|
||||
public static IntPtr GetHandle(this Window window)
|
||||
{
|
||||
var helper = new WindowInteropHelper(window);
|
||||
return helper.Handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user