简体   繁体   English

托盘图标不在Visual C ++中绘制图像

[英]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). 我在Visual Studio 2010中工作。我正在创建一个简单的应用程序,它在托盘中显示图标(任务栏)。 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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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