amirghi
amirghi

Reputation: 43

Is it possible to send Windows Toast notifications from a c++ Windows service?

I am trying to learn how to show Toast notifications from my program which is native c++ console application registered as a windows service.

I learnt that Toasts are part of the windows runtime UI components; So does this mean I have to develop a GUI component for my product in order to be able to send Toasts?

Upvotes: 2

Views: 6362

Answers (3)

mohabouje
mohabouje

Reputation: 4050

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"imagepath");
templ.setTextField(L"firstline", 0);
templ.setTextField(L"secondline", 1);

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

Upvotes: 3

mimokrokodil
mimokrokodil

Reputation: 21

You should check this. Pure unmanaged c++ & COM.

Upvotes: 2

Waqar ul islam
Waqar ul islam

Reputation: 498

Yes it might be possible check this link Here Certain WinRT classes can be used from desktop apps, including portions of the Windows.UI namespace. The toast notification APIs are one such example - they can be used by both Windows Store apps and desktop apps

Upvotes: 0

Related Questions