英文:
C create Windows Taskbar Notification
问题
如何创建一个类似这样的弹出窗口:[![Popup](https://i.stack.imgur.com/W2hvO.png)](https://i.stack.imgur.com/W2hvO.png)
我尝试了 `Shell_NotifyIcon()`,但它只在任务栏中创建了一个图标,而气球提示在Windows 10中不再起作用。也许我漏掉了什么,但我找不到其他可以实现这个功能的函数。
以下是我的设置:
```cpp
NOTIFYICONDATAA dataa;
dataa.cbSize=sizeof(dataa);
dataa.hWnd=hWnd;
dataa.uID=0;
dataa.uFlags=NIF_ICON | NIF_TIP | NIF_MESSAGE;
dataa.hIcon=LoadIcon(NULL, IDI_QUESTION);
strcpy(dataa.szTip, "Test1");
Shell_NotifyIcon(NIM_ADD, &dataa);
Shell_NotifyIcon(NIM_MODIFY, &dataa);
<details>
<summary>英文:</summary>
How do i create a Popup like this: [![Popup](https://i.stack.imgur.com/W2hvO.png)](https://i.stack.imgur.com/W2hvO.png)
I try `Shell_NotifyIcon()` but this only creates an image in the Taskbar and the Balloon function don´t work in Windows 10 anymore. Maybe i missed something but i don´t find any other function to do that.
Following is my setup:
NOTIFYICONDATAA dataa;
dataa.cbSize=sizeof(dataa);
dataa.hWnd=hWnd;
dataa.uID=0;
dataa.uFlags=NIF_ICON | NIF_TIP | NIF_MESSAGE;
dataa.hIcon=LoadIcon(NULL, IDI_QUESTION);
strcpy(dataa.szTip, "Test1");
Shell_NotifyIcon(NIM_ADD, &dataa);
Shell_NotifyIcon(NIM_MODIFY, &dataa);
</details>
# 答案1
**得分**: 1
以下是翻译好的部分:
```c
使用以下代码,我可以创建一个类似于这样的通知:
[![通知][1]][1]
NOTIFYICONDATAA dataa;
dataa.uTimeout = 3000;
dataa.uVersion = NIM_SETVERSION;
dataa.cbSize = sizeof(dataa);
dataa.hWnd = hWnd;
dataa.uID = 0;
dataa.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE | NIF_INFO;
dataa.hIcon = LoadIcon(NULL, IDI_WARNING);
dataa.dwInfoFlags = NIIF_WARNING;
strcpy(dataa.szTip, "Test1");
strcpy(dataa.szInfo, "Test2");
strcpy(dataa.szInfoTitle, "Test3");
Shell_NotifyIcon(NIM_ADD, &dataa);
Shell_NotifyIcon(NIM_SETVERSION, &dataa);
感谢 Remy 和 Jonathan。这似乎比 [toast 通知][2] 选项更容易。
在我的测试中,我只能更改 Test2 和 Test3 字符串。标题字符串我无法更改,我认为这是 Windows 的行为。运行 .exe 文件后,应用程序名称将用作标题字符串。
要生成通知并使用代码中的结构体,**必须设置版本**为
> #define _WIN32_IE 0x0650 // 或其他大于 0x600 的值
然后再包含 shellapi.h。
[1]: https://i.stack.imgur.com/YVLHv.png
[2]: https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/toast-notifications-overview
英文:
With following code i can create a Notification like this:
NOTIFYICONDATAA dataa;
dataa.uTimeout = 3000;
dataa.uVersion = NIM_SETVERSION;
dataa.cbSize = sizeof(dataa);
dataa.hWnd = hWnd;
dataa.uID = 0;
dataa.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE | NIF_INFO;
dataa.hIcon = LoadIcon(NULL, IDI_WARNING);
dataa.dwInfoFlags = NIIF_WARNING;
strcpy(dataa.szTip, "Test1");
strcpy(dataa.szInfo, "Test2");
strcpy(dataa.szInfoTitle, "Test3");
Shell_NotifyIcon(NIM_ADD, &dataa);
Shell_NotifyIcon(NIM_SETVERSION, &dataa);
Thanks to Remy and Jonathan. This seems easier than the toast notification option.
In my tests i can only change the Test2 and Test3 string. The title string i can not change, i think this do Windows. After running the .exe, the App name will used as title string.
To generate the Notification and use the struct like in code, the Version must set to
> #define _WIN32_IE 0x0650 //or other value above 0x600
before including shellapi.h.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论