简体   繁体   English

C ++ Shellapi-系统托盘气泡时的垃圾字符

[英]C++ shellapi - Garbage characters upon system tray bubbles

So I'm making a console application in C++ with win32 and shellapi (for different reasons). 所以我正在用Win32和Shellapi在C ++中制作一个控制台应用程序(出于不同的原因)。 Everything has gone well for most of it, although recently I've noticed some issues when calling the Shell_NotifyIcon() function. 尽管最近我在调用Shell_NotifyIcon()函数时注意到了一些问题,但大多数情况都进展顺利。

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 而且我得到以下结果: 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. 我想它与NOTIFYICONDATA::szInfo成员有关,但是我仍然无法解决该问题。 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). 我使用shell的工作还不多,所以如果我误解了一些主要知识(或使用不正确的东西),请原谅。 I hope I can get somewhere with this at least. 我希望我至少可以在此取得进展。

References: 参考文献:

I solved it myself, just a while after asking this strangely. 奇怪地问了一段时间后,我自己解决了这个问题。

The answer is simple: You need to set NOTIFYICONDATA::szInfoTitle to something. 答案很简单:您需要将NOTIFYICONDATA::szInfoTitle设置为某种值。 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. 现在,一切看起来都很好。

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

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