Fixed stackoverflow...
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
<AssetTargetFallback>uap10.0.19041</AssetTargetFallback>
|
<AssetTargetFallback>uap10.0.19041</AssetTargetFallback>
|
||||||
<Platforms>AnyCPU;x64</Platforms>
|
<Platforms>AnyCPU;x64</Platforms>
|
||||||
<StartupObject>NotificationFlyout.Tray.Program</StartupObject>
|
<StartupObject>NotificationFlyout.Tray.Program</StartupObject>
|
||||||
|
<LangVersion>9.0</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
+11
-1
@@ -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;
|
||||||
using Windows.UI.Xaml.Controls.Primitives;
|
using Windows.UI.Xaml.Controls.Primitives;
|
||||||
|
|
||||||
@@ -20,6 +22,14 @@ namespace NotificationFlyout.Uwp.UI.Controls
|
|||||||
|
|
||||||
_templateSettings = new NotificationFlyoutPresenterTemplateSettings();
|
_templateSettings = new NotificationFlyoutPresenterTemplateSettings();
|
||||||
SetValue(TemplateSettingsProperty, _templateSettings);
|
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
|
public NotificationFlyoutPresenterTemplateSettings TemplateSettings
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
|||||||
|
|
||||||
private NotificationFlyoutPresenter GetNotificationFlyoutPresenter()
|
private NotificationFlyoutPresenter GetNotificationFlyoutPresenter()
|
||||||
{
|
{
|
||||||
|
if (_host == null) return null;
|
||||||
return _host.GetUwpInternalObject() as NotificationFlyoutPresenter;
|
return _host.GetUwpInternalObject() as NotificationFlyoutPresenter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +155,8 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
|||||||
private void UpdateWindow()
|
private void UpdateWindow()
|
||||||
{
|
{
|
||||||
var flyoutPresenter = GetNotificationFlyoutPresenter();
|
var flyoutPresenter = GetNotificationFlyoutPresenter();
|
||||||
|
if (flyoutPresenter == null) return;
|
||||||
|
|
||||||
var taskbarState = _taskbarHelper.GetCurrentState();
|
var taskbarState = _taskbarHelper.GetCurrentState();
|
||||||
|
|
||||||
var screen = Screen.FromHandle(this.GetHandle());
|
var screen = Screen.FromHandle(this.GetHandle());
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using Microsoft.Windows.Sdk;
|
using NotificationFlyout.Wpf.UI.Extensions;
|
||||||
using NotificationFlyout.Wpf.UI.Extensions;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Windows;
|
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)]
|
[DllImport("shell32.dll", SetLastError = true)]
|
||||||
private static extern int Shell_NotifyIcon(NotifyIconCommand notifyCommand, ref NotifyIconData notifyIconData);
|
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 void RemoveNotificationIcon() => WriteNotifyIconData(NotifyIconCommand.Delete, NotifyIconDataMember.Message);
|
||||||
|
|
||||||
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||||
{
|
{
|
||||||
if (msg == CallbackMessage)
|
if (msg == CallbackMessage)
|
||||||
@@ -165,7 +166,7 @@ namespace NotificationFlyout.Wpf.UI.Helpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
private void WriteNotifyIconData(NotifyIconCommand command, NotifyIconDataMember flags)
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using Microsoft.Win32;
|
||||||
|
|
||||||
|
namespace NotificationFlyout.Wpf.UI.Helpers
|
||||||
|
{
|
||||||
|
internal static class RegistryHelper
|
||||||
|
{
|
||||||
|
public static TValue GetDwordValue<TValue>(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,30 +1,21 @@
|
|||||||
using Microsoft.Win32;
|
using NotificationFlyout.Wpf.UI.Extensions;
|
||||||
using NotificationFlyout.Wpf.UI.Extensions;
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace NotificationFlyout.Wpf.UI.Helpers
|
namespace NotificationFlyout.Wpf.UI.Helpers
|
||||||
{
|
{
|
||||||
public static class SystemSettingsHelper
|
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()
|
private static SystemTheme GetDefaultSystemTheme()
|
||||||
{
|
{
|
||||||
return Environment.OSVersion.IsGreaterThan(OperatingSystemVersion.Windows10_1809) &&
|
return Environment.OSVersion.IsGreaterThan(OperatingSystemVersion.Windows10_1809) && DoesSystemUsesLightTheme() ? SystemTheme.Light : SystemTheme.Dark;
|
||||||
ReadDword(PersonalizeKey, "SystemUsesLightTheme")
|
|
||||||
? 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);
|
var personalizeKey = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
|
||||||
using var subKey = baseKey.OpenSubKey(key);
|
return RegistryHelper.GetDwordValue<int>(personalizeKey, "SystemUsesLightTheme") > 0;
|
||||||
return subKey.GetValue<int>(valueName, defaultValue) > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsTransparencyEnabled => ReadDword(PersonalizeKey, "EnableTransparency");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
public enum SystemTheme
|
public enum SystemTheme
|
||||||
{
|
{
|
||||||
Dark,
|
Dark,
|
||||||
Light
|
Light,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,11 +72,17 @@ namespace NotificationFlyout.Wpf.UI.Helpers
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
|
private static extern IntPtr DefWindowProcW(IntPtr handle, uint msg, IntPtr wParam, IntPtr lParam);
|
||||||
|
|
||||||
private static IntPtr GetSystemTrayHandle()
|
private static IntPtr GetSystemTrayHandle()
|
||||||
{
|
{
|
||||||
return WindowHelper.GetHandle(ShellTrayHandleName);
|
return WindowHelper.GetHandle(ShellTrayHandleName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DllImport("shell32.dll", SetLastError = true)]
|
||||||
|
private static extern IntPtr SHAppBarMessage(AppBarMessage dwMessage, ref AppBarData pData);
|
||||||
|
|
||||||
private AppBarData GetAppBarData(IntPtr handle)
|
private AppBarData GetAppBarData(IntPtr handle)
|
||||||
{
|
{
|
||||||
return new AppBarData
|
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)
|
private void GetAppBarPosition(ref AppBarData appBarData)
|
||||||
{
|
{
|
||||||
SHAppBarMessage(AppBarMessage.GetTaskbarPos, ref appBarData);
|
SHAppBarMessage(AppBarMessage.GetTaskbarPos, ref appBarData);
|
||||||
@@ -112,7 +104,18 @@ namespace NotificationFlyout.Wpf.UI.Helpers
|
|||||||
TaskbarChanged?.Invoke(this, EventArgs.Empty);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user