I want my application to have an icon in the notification area in Windows 7. I used Shell_NotifyIcon to add the icon. The icon appears, but when I click the mouse over the icon, the icon disappears. The app works all the time. The icon is not hidden, it just disappears.
Shell_NotifyIcon returns a nonzero value, which means it succeeds.
Here is the relevant code:
static const int ID_TRAYICON = 300;
static const int MSG_TRAYICON = WM_USER + 1;
NOTIFYICONDATA nid;
void InitTrayIconData()
{
memset(&nid, 0, sizeof(NOTIFYICONDATA));
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hwnd;
nid.uID = ID_TRAYICON;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.uCallbackMessage = MSG_TRAYICON;
nid.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
lstrcpy(nid.szTip, TEXT("Data Aggregator in-dev version"));
}
Then, when processing the WM_CREATE message:
InitTrayIconData();
Shell_NotifyIcon(NIM_ADD, &nid);
And when processing WM_DESTROY:
Shell_NotifyIcon(NIM_DELETE, &nid);
I also noticed that for some reason, the MSG_TRAYICON message is never called.
source
share