简体   繁体   中英

Tray Icon not diplaying the Image in Visual c++

I am working in Visual Studio 2010. I am creating a simple application which shows the icon in the tray(taskbar). the problem i am facing is the application is shown in the tray(taskbar), but its icon is not shown. My code is given below

    NOTIFYICONDATA nid; 
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hWnd;
nid.uID = 100;
nid.uVersion = NOTIFYICON_VERSION;
nid.uCallbackMessage = WM_MYMESSAGE;
nid.hIcon = LoadIcon(NULL,  MAKEINTRESOURCE(IDI_ICON2));
//nid.hIcon =(HICON) hIcon;
wcscpy_s(nid.szTip, L"ultraDefender");
nid.uFlags = NIF_MESSAGE NIF_ICON NIF_TIP;
Shell_NotifyIcon(NIM_ADD, &nid);

Kindly guide me

nid.uFlags = NIF_MESSAGE NIF_ICON NIF_TIP;

should be

nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;

Also,

MAKEINTRESOURCE(IDI_ICON2)

should be

IDI_ICON2    

if this is the name of the icon

You should zero out the structure before filling it in... there are other members that you're not using where non-zero values will impact your results:

NOTIFYICONDATA nid;
ZeroMemory( &nid, sizeof(nid) );
...

additionally as noz says, your flags need to be or'd:

nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM