Windows 10 Toast Notifications桌面应用程序

问题描述 投票:10回答:3

我正在尝试将一些Windows 10功能集成到我现有的Windows桌面应用程序中。我有点卡住整合Toast Notifications。使用toast通知示例(https://code.msdn.microsoft.com/windowsdesktop/sending-toast-notifications-71e230a2/)我能够实现代码来发送和隐藏通知。它也有效,当用户点击“活动”通知时,我的应用程序中的事件处理程序被调用。

但是,只要通知在“操作中心”中“存档”,用户点击我的通知就不会发生任何事情。在这种情况下,我如何对点击做出反应?

谢谢你的帮助,

卢卡斯

c++ notifications toast windows-10
3个回答
13
投票

我开发了WinToast,一个用C ++编写的库,可以轻松集成Windows Toast Notification。我用它来在不同的项目中集成Toast通知,特别是与Qt Framework。

本机Toast Notification需要Com Fundamentals的一些功能,这些功能仅在现代版本的Windows中可用(最低支持的客户端:Windows 8)。

这就是库动态加载所有必需库的原因。使用WinToast使您的应用程序与旧版Windows兼容。附加说明如何在存储库中使用它。

要显示祝酒词,只需创建模板和自定义处理程序并启动它:

WinToastHandlerExample* handler = new WinToastHandlerExample;
WinToastTemplate templ  = WinToastTemplate(WinToastTemplate::ImageWithTwoLines);
templ.setImagePath(L"C:/example.png");
templ.setTextField(L"title", WinToastTemplate::FirstLine);
templ.setTextField(L"subtitle", WinToastTemplate::SecondLine);

if (!WinToast::instance()->showToast(templ, handler)) {
   std::wcout << L"Could not launch your toast notification!";
}

4
投票

有关于Windows 10的更新文档,描述了如何使用Win32应用程序中的Action Center(和交互式Toast):https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/send-local-toast-desktop

基本上,您必须使用COM服务器。 ToastNotification本身上的Activated事件是一个运行时事件...如果您的程序已关闭且用户从Action Center单击您的Toast,则无用。因此,Activated仅在用户首次弹出时点击您的吐司时才会触发。当用户从操作中心点击您的祝酒词时,它不会触发。这就是COM服务器的用途(或UWP应用程序中的OnActivated方法)。


3
投票

该示例适用于Windows 8; Windows 10 Tech Preview中的操作中心是新的,并且还没有SDK可供您使用任何新功能。

© www.soinside.com 2019 - 2024. All rights reserved.