Click here to Skip to main content
16,017,502 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We are trying to use Shell_NotifyIcon along with NOTIFYICONDATA structure. On Window 10, We are seeing that if we try to display the balloon notification area along with Title ICON , the ICON gets copied to temp folder everytime it is displayed. It is possible to avoid this ? We have certain use case due to which we do not want any file copy operation triggered while displaying the notifications.

Sample code we tried is as follows:
C++
void CTrayIconTestDlg::AddIconToSysTray()
{
	HICON	m_hIconInfo = NULL;//(HICON)::LoadImage(), MAKEINTRESOURCE(IDI_ICON_INFO), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR | LR_LOADTRANSPARENT);

	// TODO: Add your control notification handler code here
	NOTIFYICONDATA NID;

	memset(&NID, 0, sizeof(NID));

	//on main function:
	NID.cbSize = sizeof(NID);
	NID.hIcon = this->m_hIcon;
	
	NID.hWnd = this->m_hWnd;
	NID.uID = WM_USER + 2;
	StrCpyW(NID.szTip, L"System Tray Icon: Hello World");
	//in a timer:
	
	NID.uFlags = NID.uFlags | NIF_ICON | NIF_TIP ;
	Shell_NotifyIcon(NIM_ADD, &NID);

	//CDialogEx::OnOK();
}

void CTrayIconTestDlg::DisplayNotification()
{
	// TODO: Add your control notification handler code here
	NOTIFYICONDATA NID;
	memset(&NID, 0, sizeof(NID));
	//on main function:
	NID.cbSize = sizeof(NID);
	NID.hIcon = this->m_hIcon;
	
	NID.hWnd = this->m_hWnd;
	NID.uID = WM_USER + 2;
	StrCpyW(NID.szTip, L"System Tray Icon: Hello World");
	//in a timer:
	
	NID.uFlags = NID.uFlags | NIF_ICON | NIF_INFO | NIF_TIP ;

	StrCpyW(NID.szInfoTitle, L"This is balloon title");
	StrCpyW(NID.szInfo, L"This is balloon Information detailed");

	NID.uTimeout = 5000;
	NID.dwInfoFlags = NID.dwInfoFlags | NIIF_INFO;
	
	//NID.dwInfoFlags = NID.dwInfoFlags | NIIF_USER;
	//NID.hBalloonIcon = this->m_hIcon;

	BOOL res = Shell_NotifyIcon(NIM_MODIFY, &NID);
	if( res == FALSE )
		MessageBoxA(NULL, "False", "", MB_OK);
}


What I have tried:

1) MSDN documentation
2) Tried same code on Windows 7, it does not copy the ICON to temp folder
Posted
Updated 23-Jan-23 0:59am
v4
Comments
KarstenK 5-Aug-16 8:40am    
I dont get it!!! Even if the icon is already there?
Sounds like a bug by Microsoft. You should contact them and throw away all hope of a fix. (Sorry for that)

Hi,

It is not possible to avoid this on Windows 10. You may want to file a bug if you are using one of these products accepting bug reports:

[Microsoft Connect]

Be prepared for your bug to be closed as "By Design".

You can also use the Feedback Hub[^] to submit feedback about this feature.

Best Wishes,
-David Delaune
 
Share this answer
 
#include <Windows.h>

int main()
{

  // Create a NOTIFYICONDATA structure
  NOTIFYICONDATA nid;
  ZeroMemory(&nid, sizeof(nid));
  nid.cbSize = sizeof(nid);
  nid.hWnd = NULL;
  nid.uID = 1;
  nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  nid.uCallbackMessage = WM_USER;
  nid.uTimeout = 15;
  HANDLE hIcon = LoadImageW(NULL, L"icon.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
  if (hIcon == NULL)
  {
    // handle error
  }
  else
  {
    nid.hIcon = LoadIcon((HINSTANCE)hIcon, IDI_APPLICATION);
  }

  lstrcpy(nid.szTip, L"My Notification");

  // Show the notification
  Shell_NotifyIcon(NIM_ADD, &nid);

  // Show a balloon notification
  nid.uFlags = NIF_INFO;
  lstrcpy(nid.szInfo, L"message!");
  lstrcpy(nid.szInfoTitle, L"Title");
  nid.dwInfoFlags = NIIF_ERROR;
  Shell_NotifyIcon(NIM_MODIFY, &nid);

  // Wait for the user to dismiss the notification
  Sleep(3000);

  // Remove the notification
  Shell_NotifyIcon(NIM_DELETE, &nid);

  return 0;
}
 
Share this answer
 
Comments
Richard Deeming 23-Jan-23 7:21am    
An unexplained code-dump as a new solution to a question from 6½ years ago is not acceptable.

Click the green "Improve solution" link and update your solution to explain how your code differs from the code in the question, and how it solves the problem from the question.
Vinod Kc 26-Jul-24 21:23pm    
And the code has some errors also. He just created an HICON but if it not null, he used another one instead if using the already created one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900