I'm trying to integrate some Windows 10 features into my existing Windows Desktop application. I am a little stuck integrating the Toast Notifications. Using the toast notification example I was able to implement code to send and hide notifications. It also works, that when the user clicks on an 'active' notification an event handler in my application is invoked.
However, as soon as the notification is 'archived' in the 'Action Center', nothing happens when the user clicks on my notification. How can I react to clicks in such situations?
Toast notifications are similar to a popup message. These notifications provide time-sensitive information about events that occur while an application is running. Toast notifications appear in the foreground whether Windows is currently in desktop mode, displaying the lock screen, or running another application.
Action Center in Windows 10 is where you'll find your notifications and quick actions. Change your settings at any time to adjust how and when you see notifications and which apps and settings are your top quick actions. Select Start . Select Settings > System > Notifications & actions.
A toast is a small display on the bottom of the screen. A notification is displayed in the top menu bar.
I have developed WinToast, a library written in C++ to integrate Windows Toast Notification easily. I have used it to integrate Toast notifications in different projects, specially with Qt Framework.
The native Toast Notification needs some functions of the Com Fundamentals which are availables only in moderns version of Windows (minimum supported client: Windows 8).
That's why the library loads all the required libraries dynamically. Make your application compatible with older versions of Windows using WinToast. There is an attached example explaining how to use it in the repository.
To show a toast, just create the template and your custom handler and launch it:
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!";
}
There's updated documentation for Windows 10 describing how to use Action Center (and interactive toasts) from a Win32 app: https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/send-local-toast-desktop
Basically, you have to use a COM server. The Activated event on the ToastNotification itself is a runtime event... useless if your program has been closed and the user clicks on your toast from Action Center. Thus, Activated only fires if the user clicks your toast when it first pops up. It does NOT fire when the user clicks your toast from Action Center. That's what the COM server is for (or what the OnActivated method in UWP apps is for).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With