Windows 10 Toast Notifications Desktop Application

Lukas picture Lukas · Feb 19, 2015 · Viewed 17k times · Source

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 (https://code.msdn.microsoft.com/windowsdesktop/sending-toast-notifications-71e230a2/) 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?

Thanks for your help,

Lukas

Answer

mohabouje picture mohabouje · Oct 3, 2016

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!";
}