winforms icon indicating copy to clipboard operation
winforms copied to clipboard

NotifyIcon.Icon updates not displayed in Notifications in Windows 11

Open elixss opened this issue 1 year ago • 1 comments

.NET version

.NET 8

Did it work in .NET Framework?

Not tested/verified

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Yes, .NET 6, 7 and 8 on Windows 10.

Issue description

Hello!

I stumbled accross some sort of bug.

When using the NotifyIcon class and setting an icon, the notifications sent by that NotifyIcon using ShowBalloonTip don't match if that icon was updated. This only happens on Windows 11. I tested it on various machines, 3 Windows 10 machines and 3 windows 11 machines, one of them Windows 11 machines was 24H2. all windows 10 were 22H2.

Steps to reproduce

I created a repo for that! https://github.com/elixss/NotifyIconTest

Clone it, run it and compare: on windows 10 the icons will match from notifications and tray, on windows 11 they won't.

elixss avatar Oct 23 '24 09:10 elixss

sorry if i missed tags i don't do this very often this is a BUG i want to report this as a bug.

elixss avatar Oct 23 '24 09:10 elixss

@Olina-Zhang can repro this issue?

JeremyKuhne avatar Oct 23 '24 16:10 JeremyKuhne

@JeremyKuhne yes, we can repro this issue in Win11 OS, please check below details:

In Win10 machine (.NET 6.0, .NET 8.0, .NET 9.0, .NET 10.0 and .NET Framework 4.8.1 all are the same result):

Image

https://github.com/user-attachments/assets/b2e18325-dde0-4780-b5fb-b130c0e79fec

In Win11 machine (.NET 6.0, .NET 8.0, .NET 9.0, .NET 10.0 and .NET Framework 4.8.1 all are the same result):

Image

https://github.com/user-attachments/assets/ffc0e959-b824-4c31-90ff-f9375cea11fe

John-Qiao avatar Oct 24 '24 09:10 John-Qiao

I see you got the same result. Is this a bug or an intended change?

elixss avatar Oct 29 '24 13:10 elixss

@Olina-Zhang can you check the AzDO instance to see if they have a bug there already tracking this on the Windows side? @LeafShi1 can your team create an MFC application that mimics our NotifyIcon behavior to see if this is also reproduced in native code?

merriemcgaw avatar Oct 31 '24 18:10 merriemcgaw

@Olina-Zhang can you check the AzDO instance to see if they have a bug there already tracking this on the Windows side?

No AzDo Windows bug related this issue exists.

Olina-Zhang avatar Nov 01 '24 09:11 Olina-Zhang

Try to use Shell_NotifyIcon simulation, but in win11, the notification message cannot pop up. nid.hIcon = LoadIcon(NULL, IDI_WARNING) control which icon is displayed. How the icon mentioned in the question is displayed is not within the control range of our code. We can only set the following icon in the code

Image

#include <windows.h>
#include <strsafe.h>

BOOL CMFCApplication1Dlg::OnInitDialog()
{
	NOTIFYICONDATAW nid;
	ZeroMemory(&nid, sizeof(nid));
	nid.cbSize = sizeof(nid);
	nid.hWnd = NULL;
	nid.uID = 1;
	nid.uFlags = NIF_INFO | NIF_MESSAGE | NIF_ICON;
	nid.hIcon = LoadIcon(NULL, IDI_WARNING);
	nid.uCallbackMessage = WM_USER + 1;
	StringCchCopy(nid.szTip, ARRAYSIZE(nid.szTip), L"Tip");
	StringCchCopy(nid.szInfo, ARRAYSIZE(nid.szInfo), L"This is a warning");
	StringCchCopy(nid.szInfoTitle, ARRAYSIZE(nid.szInfoTitle), L"Warning");
	nid.dwInfoFlags = NIIF_WARNING;
	Shell_NotifyIcon(NIM_ADD, &nid);
	Shell_NotifyIcon(NIM_MODIFY, &nid);
	Sleep(5000);
	Shell_NotifyIcon(NIM_DELETE, &nid);
}

LeafShi1 avatar Nov 01 '24 10:11 LeafShi1

@elixss On win11, it does not support changing the tray icon. Please see the sample program for details. WinFormsApp5.zip

LeafShi1 avatar Nov 05 '24 10:11 LeafShi1