Say, I created my icon:
//'ghIcon' of type HICON
ghIcon = LoadImage(m_hInstance, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, nCx, nCy, 0);
and then set it to be displayed on system tray:
NOTIFYICONDATA nid;
memset(&nid, 0, sizeof(nid));
nid.cbSize = sizeof(nid);
nid.hWnd = hMyWnd;
nid.uID = TRAY_ICON_ID1;
nid.uFlags = NIF_ICON;
nid.uCallbackMessage = TRAY_NOTIFICATION_ID1;
nid.hIcon = ghIcon;
Shell_NotifyIcon(NIM_ADD, &nid);
and then at some point I want to replace it with a new icon:
if(ghIcon)
{
//Delete old icon first
DestroyIcon(ghIcon);
}
//Load new icon
ghIcon = LoadImage(m_hInstance, MAKEINTRESOURCE(IDI_ICON2), IMAGE_ICON, nCx, nCy, 0);
NOTIFYICONDATA nid;
memset(&nid, 0, sizeof(nid));
nid.cbSize = sizeof(nid);
nid.hWnd = hMyWnd;
nid.uID = TRAY_ICON_ID1;
nid.uFlags = NIF_ICON;
nid.hIcon = ghIcon;
Shell_NotifyIcon(NIM_MODIFY, &nid);
My question is, can I delete the previous icon while it's still selected in system tray, like I showed above? Or, do I need to change it to something else first and then call DestroyIcon
on it?
PS. My actual example is obviously not as simple as I showed above. I'm just curious about the concept.