The icon added to the notification tray disappears on

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);
    //nid.uVersion = NOTIFYICON_VERSION_4;
    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.

+5
source share
2 answers

. InitTrayIconData() WM_CREATE, hwnd , CreateWindowEx ( WM_CREATE CreateWindowEx, , ). , ,

nid.hWnd = hwnd;

nid.hWnd nullptr ( , hwnd).

, hwnd WndProc InitTrayIconData(), hwnd hwnd.

+6

, , .

, . , . , , , , . , MSG_TRAYICON.

+5

All Articles