16

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

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

谢谢你的帮助,

卢卡斯

4

3 回答 3

23

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

本机 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!";
}
于 2016-10-03T18:36:34.423 回答
8

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

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

于 2015-12-03T17:16:32.003 回答
3

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

于 2015-02-28T23:33:11.640 回答