Browse Source

Enable tray icon creation in all circumstances when running as an admin (#19382)

* Fix trayicon unable to create

* Revert "Fix trayicon unable to create"

This reverts commit 4f397dbcdf.

* Fix trayicon unable to create

* Use ChangeWindowMessageFilterEx  in Win32Platform.CreateMessageWindow

* modify the format

* Change the enum from ChangeWindowMessageFilterEx

* Change the enum from ChangeWindowMessageFilterEx
pull/19417/head
lwz-sabrina 1 year ago
committed by GitHub
parent
commit
27bba4c386
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 15
      src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs
  2. 7
      src/Windows/Avalonia.Win32/TrayIconImpl.cs
  3. 2
      src/Windows/Avalonia.Win32/Win32Platform.cs

15
src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs

@ -1502,6 +1502,21 @@ namespace Avalonia.Win32.Interop
[DllImport("shell32", CharSet = CharSet.Auto)]
public static extern int Shell_NotifyIcon(NIM dwMessage, NOTIFYICONDATA lpData);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool ChangeWindowMessageFilterEx(
IntPtr hWnd,
uint message,
MessageFilterFlag action,
IntPtr pChangeFilterStruct
);
public enum MessageFilterFlag
{
MSGFLT_RESET = 0,
MSGFLT_ALLOW = 1,
MSGFLT_DISALLOW = 2,
}
[DllImport("shell32", CharSet = CharSet.Auto)]
public static extern nint SHAppBarMessage(AppBarMessage dwMessage, ref APPBARDATA lpData);

7
src/Windows/Avalonia.Win32/TrayIconImpl.cs

@ -37,7 +37,12 @@ namespace Avalonia.Win32
new PixelSize(32, 32), new Vector(96, 96), PixelFormats.Bgra8888, AlphaFormat.Unpremul);
s_emptyIcon = new Win32Icon(bitmap);
}
internal static void ChangeWindowMessageFilter(IntPtr hWnd)
{
ChangeWindowMessageFilterEx(hWnd, WM_TASKBARCREATED, MessageFilterFlag.MSGFLT_ALLOW, IntPtr.Zero);
}
public TrayIconImpl()
{
FindTaskBarMonitor();

2
src/Windows/Avalonia.Win32/Win32Platform.cs

@ -218,6 +218,8 @@ namespace Avalonia.Win32
{
throw new Win32Exception();
}
TrayIconImpl.ChangeWindowMessageFilter(_hwnd);
}
public ITrayIconImpl CreateTrayIcon()

Loading…
Cancel
Save