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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
23 additions and
1 deletions
src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs
src/Windows/Avalonia.Win32/TrayIconImpl.cs
src/Windows/Avalonia.Win32/Win32Platform.cs
@ -1502,6 +1502,21 @@ namespace Avalonia.Win32.Interop
[DllImport("shell32", CharSet = CharSet.Auto)]
[DllImport("shell32", CharSet = CharSet.Auto)]
public static extern int Shell_NotifyIcon ( NIM dwMessage , NOTIFYICONDATA lpData ) ;
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)]
[DllImport("shell32", CharSet = CharSet.Auto)]
public static extern nint SHAppBarMessage ( AppBarMessage dwMessage , ref APPBARDATA lpData ) ;
public static extern nint SHAppBarMessage ( AppBarMessage dwMessage , ref APPBARDATA lpData ) ;
@ -37,7 +37,12 @@ namespace Avalonia.Win32
new PixelSize ( 3 2 , 3 2 ) , new Vector ( 9 6 , 9 6 ) , PixelFormats . Bgra8888 , AlphaFormat . Unpremul ) ;
new PixelSize ( 3 2 , 3 2 ) , new Vector ( 9 6 , 9 6 ) , PixelFormats . Bgra8888 , AlphaFormat . Unpremul ) ;
s_emptyIcon = new Win32Icon ( bitmap ) ;
s_emptyIcon = new Win32Icon ( bitmap ) ;
}
}
internal static void ChangeWindowMessageFilter ( IntPtr hWnd )
{
ChangeWindowMessageFilterEx ( hWnd , WM_TASKBARCREATED , MessageFilterFlag . MSGFLT_ALLOW , IntPtr . Zero ) ;
}
public TrayIconImpl ( )
public TrayIconImpl ( )
{
{
FindTaskBarMonitor ( ) ;
FindTaskBarMonitor ( ) ;
@ -218,6 +218,8 @@ namespace Avalonia.Win32
{
{
throw new Win32Exception ( ) ;
throw new Win32Exception ( ) ;
}
}
TrayIconImpl . ChangeWindowMessageFilter ( _ hwnd ) ;
}
}
public ITrayIconImpl CreateTrayIcon ( )
public ITrayIconImpl CreateTrayIcon ( )