Question

So I'm making a console application in C++ with win32 and shellapi (for different reasons). Everything has gone well for most of it, although recently I've noticed some issues when calling the Shell_NotifyIcon() function.

I got this piece of code:

NOTIFYICONDATA s_data;
s_data.cbSize = sizeof(s_data);
s_data.uFlags = NIF_INFO;
s_data.dwInfoFlags = NIIF_NONE;
s_data.uTimeout = 1;
StringCchCopy(s_data.szInfo, ARRAYSIZE(s_data.szInfo), L"Test message");
Shell_NotifyIcon(NIM_ADD, &s_data);

I've included the following (relevant) header files:

#include <Windows.h>
#include <Shellapi.h>
#include <Strsafe.h>

And I get the following result: http://prntscr.com/2s5e3i

I suppose it has to do with the NOTIFYICONDATA::szInfo member, but I still can't figure out a fix to it. And considering that I've double checked with some examples online (whereas the difference has been minimal), I doubt that it's something really obvious.

Thanks in advance. I haven't been working with shell that much, so excuse me if I'm misunderstanding something major or so (or using something incorrectly). I hope I can get somewhere with this at least.

References:

Était-ce utile?

La solution

I solved it myself, just a while after asking this strangely.

The answer is simple: You need to set NOTIFYICONDATA::szInfoTitle to something. In my case, I completely forgot about it, and expected it to use some sort of default title, but it didn't. Instead, it got replaced by garbage, making it unreadable.

To solve it, I added:

StringCchCopy(s_data.szInfoTitle, ARRAYSIZE(s_data.szInfoTitle), L"Test title");

And now everything appear neatly.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top