BOOL CTrayIcon::SetIcon(HICON hicon, LPCTSTR lpTip, UINT uID)
{
UINT msg;
m_nid.uFlags =NIF_ICON|NIF_TIP;
// Set the icon
if (hicon)
{
// Add or replace icon in system tray
msg = m_nid.hIcon ? NIM_MODIFY : NIM_ADD;
m_nid.hIcon = hicon;
}
else
{ // remove icon from tray
if (m_nid.hIcon==NULL)
return TRUE; // already deleted
msg = NIM_DELETE;
}
// Use the tip, if any
if (lpTip)
wcscpy(m_nid.szTip,lpTip);
// Use callback if any
if (m_nid.uCallbackMessage && m_nid.hWnd)
m_nid.uFlags |= NIF_MESSAGE;
// Do it
BOOL bRet = Shell_NotifyIcon(msg, &m_nid);
if (msg==NIM_DELETE || !bRet)
m_nid.hIcon = NULL; // failed
}