Windows 10 Toast Notifications桌面应用程序

Luk*_*kas 11 c++ notifications toast windows-10

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

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

谢谢你的帮助,

卢卡斯

moh*_*uje 14

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

本机Toast通知需要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!";
}
Run Code Online (Sandbox Code Playgroud)


And*_*der 7

Windows 10 的更新文档描述了如何从 Win32 应用程序使用操作中心(和交互式 toast):https : //docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/发送本地吐司桌面

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


Pet*_*SFT 3

该示例适用于 Windows 8;Windows 10 技术预览版中的操作中心是新的,目前还没有 SDK 可供您使用任何新功能。