summaryrefslogtreecommitdiff
path: root/plugins/Toaster/src/toast_notification.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Toaster/src/toast_notification.cpp')
-rw-r--r--plugins/Toaster/src/toast_notification.cpp44
1 files changed, 16 insertions, 28 deletions
diff --git a/plugins/Toaster/src/toast_notification.cpp b/plugins/Toaster/src/toast_notification.cpp
index af89e779d1..941bacbefc 100644
--- a/plugins/Toaster/src/toast_notification.cpp
+++ b/plugins/Toaster/src/toast_notification.cpp
@@ -1,5 +1,7 @@
#include "stdafx.h"
+using namespace Microsoft::WRL;
+
ToastNotification::ToastNotification(_In_ wchar_t* text, _In_ wchar_t* caption, _In_ wchar_t* imagePath)
: _text(text), _caption(caption), _imagePath(imagePath)
{
@@ -11,24 +13,15 @@ ToastNotification::~ToastNotification()
HRESULT ToastNotification::Initialize()
{
- HRESULT hr = Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager).Get(), &notificationManager);
- if (SUCCEEDED(hr))
- {
- hr = notificationManager->CreateToastNotifierWithId(StringReferenceWrapper(::AppUserModelID).Get(), &notifier);
- if (SUCCEEDED(hr))
- {
- hr = Create(&notification);
- }
- }
- return hr;
+ CHECKHR(Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager).Get(), &notificationManager));
+ CHECKHR(notificationManager->CreateToastNotifierWithId(StringReferenceWrapper(::AppUserModelID).Get(), &notifier))
+ return Create(&notification);
}
HRESULT ToastNotification::CreateXml(_Outptr_ ABI::Windows::Data::Xml::Dom::IXmlDocument** xml)
{
- Microsoft::WRL::ComPtr<ABI::Windows::Data::Xml::Dom::IXmlDocumentIO> xmlDocument;
- HRESULT hr = Windows::Foundation::ActivateInstance(StringReferenceWrapper(RuntimeClass_Windows_Data_Xml_Dom_XmlDocument).Get(), &xmlDocument);
- if (FAILED(hr))
- return hr;
+ ComPtr<ABI::Windows::Data::Xml::Dom::IXmlDocumentIO> xmlDocument;
+ CHECKHR(Windows::Foundation::ActivateInstance(StringReferenceWrapper(RuntimeClass_Windows_Data_Xml_Dom_XmlDocument).Get(), &xmlDocument));
HXML xmlToast = xmlCreateNode(L"toast", NULL, 0);
HXML xmlAudioNode = xmlAddChild(xmlToast, L"audio", NULL);
@@ -57,25 +50,20 @@ HRESULT ToastNotification::CreateXml(_Outptr_ ABI::Windows::Data::Xml::Dom::IXml
TCHAR *xtmp = xmlToString(xmlToast, NULL);
size_t xlen = mir_tstrlen(xtmp);
- hr = xmlDocument->LoadXml(StringReferenceWrapper(xtmp, xlen).Get());
- if (FAILED(hr))
- return hr;
+ CHECKHR(xmlDocument->LoadXml(StringReferenceWrapper(xtmp, xlen).Get()));
return xmlDocument.CopyTo(xml);
}
HRESULT ToastNotification::Create(_Outptr_ ABI::Windows::UI::Notifications::IToastNotification** _notification)
{
- Microsoft::WRL::ComPtr<ABI::Windows::Data::Xml::Dom::IXmlDocument> xml;
- HRESULT hr = CreateXml(&xml);
- if (FAILED(hr))
- return hr;
-
- Microsoft::WRL::ComPtr<ABI::Windows::UI::Notifications::IToastNotificationFactory> factory;
- hr = Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotification).Get(), &factory);
- if (FAILED(hr))
- return hr;
- return hr = factory->CreateToastNotification(xml.Get(), _notification);
+ ComPtr<ABI::Windows::Data::Xml::Dom::IXmlDocument> xml;
+ CHECKHR(CreateXml(&xml));
+
+ ComPtr<ABI::Windows::UI::Notifications::IToastNotificationFactory> factory;
+ CHECKHR(Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotification).Get(), &factory));
+
+ return factory->CreateToastNotification(xml.Get(), _notification);
}
HRESULT ToastNotification::Show()
@@ -86,7 +74,7 @@ HRESULT ToastNotification::Show()
HRESULT ToastNotification::Show(_In_ ToastEventHandler* handler)
{
EventRegistrationToken activatedToken, dismissedToken, failedToken;
- Microsoft::WRL::ComPtr<ToastEventHandler> eventHandler(handler);
+ ComPtr<ToastEventHandler> eventHandler(handler);
notification->add_Activated(eventHandler.Get(), &activatedToken);
notification->add_Dismissed(eventHandler.Get(), &dismissedToken);