diff --git a/NotificationFlyout.Tray/NotificationFlyout.Tray.csproj b/NotificationFlyout.Tray/NotificationFlyout.Tray.csproj index 2e6895c..4f1c3fb 100644 --- a/NotificationFlyout.Tray/NotificationFlyout.Tray.csproj +++ b/NotificationFlyout.Tray/NotificationFlyout.Tray.csproj @@ -7,6 +7,7 @@ uap10.0.19041 AnyCPU;x64 NotificationFlyout.Tray.Program + 9.0 diff --git a/NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.cs b/NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.cs index 611daee..750002c 100644 --- a/NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.cs +++ b/NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.cs @@ -1,4 +1,6 @@ -using Windows.UI.Xaml; +using Windows.UI.Popups; +using Windows.UI.ViewManagement; +using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; @@ -20,6 +22,14 @@ namespace NotificationFlyout.Uwp.UI.Controls _templateSettings = new NotificationFlyoutPresenterTemplateSettings(); SetValue(TemplateSettingsProperty, _templateSettings); + + UISettings uiSettings = new UISettings(); + uiSettings.ColorValuesChanged += UiSettings_ColorValuesChanged; + } + + private void UiSettings_ColorValuesChanged(UISettings sender, object args) + { + MessageDialog d = new MessageDialog("", ""); } public NotificationFlyoutPresenterTemplateSettings TemplateSettings diff --git a/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutXamlHost.cs b/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutXamlHost.cs index a30e010..bc613eb 100644 --- a/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutXamlHost.cs +++ b/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutXamlHost.cs @@ -80,6 +80,7 @@ namespace NotificationFlyout.Wpf.UI.Controls private NotificationFlyoutPresenter GetNotificationFlyoutPresenter() { + if (_host == null) return null; return _host.GetUwpInternalObject() as NotificationFlyoutPresenter; } @@ -154,6 +155,8 @@ namespace NotificationFlyout.Wpf.UI.Controls private void UpdateWindow() { var flyoutPresenter = GetNotificationFlyoutPresenter(); + if (flyoutPresenter == null) return; + var taskbarState = _taskbarHelper.GetCurrentState(); var screen = Screen.FromHandle(this.GetHandle()); diff --git a/NotificationFlyout.Wpf.UI/Extensions/RegistryKeyExtensions.cs b/NotificationFlyout.Wpf.UI/Extensions/RegistryKeyExtensions.cs deleted file mode 100644 index 7060f66..0000000 --- a/NotificationFlyout.Wpf.UI/Extensions/RegistryKeyExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.Win32; - -namespace NotificationFlyout.Wpf.UI.Extensions -{ - public static class RegistryKeyExtensions - { - public static T GetValue(this RegistryKey self, string valueName, T defaultValue) - { - return self.GetValue(valueName, defaultValue) is T t ? t : defaultValue; - } - } -} diff --git a/NotificationFlyout.Wpf.UI/Helpers/NotificationIconHelper.cs b/NotificationFlyout.Wpf.UI/Helpers/NotificationIconHelper.cs index 73b02ea..0bce1fd 100644 --- a/NotificationFlyout.Wpf.UI/Helpers/NotificationIconHelper.cs +++ b/NotificationFlyout.Wpf.UI/Helpers/NotificationIconHelper.cs @@ -1,5 +1,4 @@ -using Microsoft.Windows.Sdk; -using NotificationFlyout.Wpf.UI.Extensions; +using NotificationFlyout.Wpf.UI.Extensions; using System; using System.Runtime.InteropServices; using System.Windows; @@ -97,6 +96,9 @@ namespace NotificationFlyout.Wpf.UI.Helpers } } + [DllImport("user32.dll", SetLastError = true)] + private static extern IntPtr DefWindowProcW(IntPtr handle, uint msg, IntPtr wParam, IntPtr lParam); + [DllImport("shell32.dll", SetLastError = true)] private static extern int Shell_NotifyIcon(NotifyIconCommand notifyCommand, ref NotifyIconData notifyIconData); @@ -133,7 +135,6 @@ namespace NotificationFlyout.Wpf.UI.Helpers } private void RemoveNotificationIcon() => WriteNotifyIconData(NotifyIconCommand.Delete, NotifyIconDataMember.Message); - private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == CallbackMessage) @@ -164,8 +165,8 @@ namespace NotificationFlyout.Wpf.UI.Helpers IconInvoked?.Invoke(this, new NotificationIconInvokedEventArgs { MouseButton = mouseButton }); } } - - return (IntPtr)(int)PInvoke.DefWindowProc((HWND)hwnd, (uint)msg, (WPARAM)(UIntPtr)(uint)wParam, (LPARAM)lParam); + + return DefWindowProcW(hwnd, (uint)msg, wParam, (lParam)); } private void WriteNotifyIconData(NotifyIconCommand command, NotifyIconDataMember flags) diff --git a/NotificationFlyout.Wpf.UI/Helpers/RegistryHelper.cs b/NotificationFlyout.Wpf.UI/Helpers/RegistryHelper.cs new file mode 100644 index 0000000..d5ad730 --- /dev/null +++ b/NotificationFlyout.Wpf.UI/Helpers/RegistryHelper.cs @@ -0,0 +1,15 @@ +using Microsoft.Win32; + +namespace NotificationFlyout.Wpf.UI.Helpers +{ + internal static class RegistryHelper + { + public static TValue GetDwordValue(string key, string valueName) + { + using var baseKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64); + using var subKey = baseKey.OpenSubKey(key); + + return (TValue)subKey.GetValue(valueName, 0); + } + } +} diff --git a/NotificationFlyout.Wpf.UI/Helpers/SystemSettingsHelper.cs b/NotificationFlyout.Wpf.UI/Helpers/SystemSettingsHelper.cs index 25eb42f..b0d4d37 100644 --- a/NotificationFlyout.Wpf.UI/Helpers/SystemSettingsHelper.cs +++ b/NotificationFlyout.Wpf.UI/Helpers/SystemSettingsHelper.cs @@ -1,30 +1,21 @@ -using Microsoft.Win32; -using NotificationFlyout.Wpf.UI.Extensions; +using NotificationFlyout.Wpf.UI.Extensions; using System; namespace NotificationFlyout.Wpf.UI.Helpers { public static class SystemSettingsHelper { - private static readonly string PersonalizeKey = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"; - - public static SystemTheme DefaultSystemTheme => GetDefaultSystemTheme(); + public static SystemTheme DefaultSystemTheme => GetDefaultSystemTheme(); private static SystemTheme GetDefaultSystemTheme() { - return Environment.OSVersion.IsGreaterThan(OperatingSystemVersion.Windows10_1809) && - ReadDword(PersonalizeKey, "SystemUsesLightTheme") - ? SystemTheme.Light - : SystemTheme.Dark; + return Environment.OSVersion.IsGreaterThan(OperatingSystemVersion.Windows10_1809) && DoesSystemUsesLightTheme() ? SystemTheme.Light : SystemTheme.Dark; } - private static bool ReadDword(string key, string valueName, int defaultValue = 0) + private static bool DoesSystemUsesLightTheme() { - using var baseKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64); - using var subKey = baseKey.OpenSubKey(key); - return subKey.GetValue(valueName, defaultValue) > 0; + var personalizeKey = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"; + return RegistryHelper.GetDwordValue(personalizeKey, "SystemUsesLightTheme") > 0; } - - public static bool IsTransparencyEnabled => ReadDword(PersonalizeKey, "EnableTransparency"); } } diff --git a/NotificationFlyout.Wpf.UI/Helpers/SystemTheme.cs b/NotificationFlyout.Wpf.UI/Helpers/SystemTheme.cs index 50b6ceb..251bb9a 100644 --- a/NotificationFlyout.Wpf.UI/Helpers/SystemTheme.cs +++ b/NotificationFlyout.Wpf.UI/Helpers/SystemTheme.cs @@ -3,6 +3,6 @@ public enum SystemTheme { Dark, - Light + Light, } } diff --git a/NotificationFlyout.Wpf.UI/Helpers/TaskbarHelper.cs b/NotificationFlyout.Wpf.UI/Helpers/TaskbarHelper.cs index 58361dd..6808b48 100644 --- a/NotificationFlyout.Wpf.UI/Helpers/TaskbarHelper.cs +++ b/NotificationFlyout.Wpf.UI/Helpers/TaskbarHelper.cs @@ -72,11 +72,17 @@ namespace NotificationFlyout.Wpf.UI.Helpers return state; } + [DllImport("user32.dll", SetLastError = true)] + private static extern IntPtr DefWindowProcW(IntPtr handle, uint msg, IntPtr wParam, IntPtr lParam); + private static IntPtr GetSystemTrayHandle() { return WindowHelper.GetHandle(ShellTrayHandleName); } + [DllImport("shell32.dll", SetLastError = true)] + private static extern IntPtr SHAppBarMessage(AppBarMessage dwMessage, ref AppBarData pData); + private AppBarData GetAppBarData(IntPtr handle) { return new AppBarData @@ -86,20 +92,6 @@ namespace NotificationFlyout.Wpf.UI.Helpers }; } - [StructLayout(LayoutKind.Sequential)] - private struct AppBarData - { - public uint cbSize; - public IntPtr hWnd; - public uint uCallbackMessage; - public AppBarEdge uEdge; - public RECT rect; - public int lParam; - } - - [DllImport("shell32.dll", SetLastError = true)] - private static extern IntPtr SHAppBarMessage(AppBarMessage dwMessage, ref AppBarData pData); - private void GetAppBarPosition(ref AppBarData appBarData) { SHAppBarMessage(AppBarMessage.GetTaskbarPos, ref appBarData); @@ -112,7 +104,18 @@ namespace NotificationFlyout.Wpf.UI.Helpers TaskbarChanged?.Invoke(this, EventArgs.Empty); } - return (IntPtr)(int)PInvoke.DefWindowProc((HWND)hwnd, (uint)msg, (WPARAM)(UIntPtr)(uint)wParam, (LPARAM)lParam); + return DefWindowProcW(hwnd, (uint)msg, wParam, (lParam)); + } + + [StructLayout(LayoutKind.Sequential)] + private struct AppBarData + { + public uint cbSize; + public IntPtr hWnd; + public uint uCallbackMessage; + public AppBarEdge uEdge; + public RECT rect; + public int lParam; } } }