I'm writing a c++ Win32 Desktop app which shows a Toast notification containing a progress bar. I'm trying to bind this progress bar with my application in order to be able to update it.
The Toast interface containing the progress bar is defined as follow:
<toast>
<visual>
<binding template='ToastGeneric'>
<text>Backup in progress</text>
<progress title='Working folder' value='0' status='Starting backup...' valueStringOverride='0/1 files' />
</binding>
</visual>
</toast>
I'm using the below code to show the Toast:
HRESULT CreateNotificationData(ABI::Windows::UI::Notifications::INotificationData** pData)
{
if (!pData)
return E_INVALIDARG;
*pData = nullptr;
IInspectable* pInstance;
HRESULT hr = ::RoActivateInstance(Microsoft::WRL::Wrappers::HStringReference(RuntimeClass_Windows_UI_Notifications_NotificationData).Get(),
&pInstance);
if (FAILED(hr))
return hr;
hr = pInstance->QueryInterface(pData);
pInstance->Release();
return hr;
}
bool ShowProgress(const std::wstring toastContent)
{
if (!toastContent.length())
return false;
// build the XML from the Toast content
::CComPtr<ABI::Windows::Data::Xml::Dom::IXmlDocument> pDoc;
HRESULT hr = DesktopNotificationManagerCompat::CreateXmlDocumentFromString(toastContent.c_str(), &pDoc);
if (FAILED(hr))
return false;
// create the notifier. Classic Win32 apps MUST use the Compat method to create the notifier
::CComPtr<ABI::Windows::UI::Notifications::IToastNotifier> pNotifier;
hr = DesktopNotificationManagerCompat::CreateToastNotifier(&pNotifier);
if (FAILED(hr))
return false;
// create the Toast notification (using helper method from Compat library)
::CComPtr<ABI::Windows::UI::Notifications::IToastNotification> pToast;
hr = DesktopNotificationManagerCompat::CreateToastNotification(pDoc, &pToast);
if (FAILED(hr))
return false;
// get the IToastNotification4 interface, which contains the required data binding functions
::CComPtr<ABI::Windows::UI::Notifications::IToastNotification4> pToastData;
hr = pToast->QueryInterface(ABI::Windows::UI::Notifications::IID_IToastNotification4, (void**)&pToastData);
if (FAILED(hr))
return false;
// create a notification data instance
::CComPtr<ABI::Windows::UI::Notifications::INotificationData> pNotificationData;
hr = CreateNotificationData(&pNotificationData);
if (FAILED(hr))
return false;
// get the values map from the Toast
::CComPtr<__FIMap_2_HSTRING_HSTRING> pValues;
hr = pNotificationData->get_Values(&pValues);
if (FAILED(hr))
return false;
// create the values to bind
HSTRING pValue;
::WindowsCreateString(L"value", 5, &pValue);
HSTRING pValueVal;
::WindowsCreateString(L"0.1", 3, &pValueVal);
HSTRING pStatus;
::WindowsCreateString(L"status", 6, &pStatus);
HSTRING pStatusVal;
::WindowsCreateString(L"Test test test", 14, &pStatusVal);
boolean replaced;
// add the values in the Toast values map as a key/value pair value
pValues->Insert(pValue, pValueVal, &replaced);
pValues->Insert(pStatus, pStatusVal, &replaced);
::WindowsDeleteString(pValue);
::WindowsDeleteString(pValueVal);
::WindowsDeleteString(pStatus);
::WindowsDeleteString(pStatusVal);
// set the sequence number to 1 in order to refresh the interface (need to be increased
// every time the Toast should be refreshed)
hr = pNotificationData->put_SequenceNumber(1);
if (FAILED(hr))
return false;
// set the data to bind in the Toast
hr = pToastData->put_Data(pNotificationData);
if (FAILED(hr))
return false;
// show the Toast
hr = pNotifier->Show(pToast);
if (FAILED(hr))
return false;
return true;
}
This code builds and executes without problems, unfortunately my progress bar is not updated.
As you can see, this code is very similar to (indeed based on) the following examples:
There is a difference, however. These examples insert the notification data into the progress component, whereas I insert the notification data into the root Toast component, as you can see on the below screenshot.
Unfortunately, if I know how to access to the Toast root component, I have absolutely no idea about how to get the child progress component contained in my Toast, and how to bind my values in it.
So the question is: how may I access the child progress component in my Toast and bind my values with it, considering that my application is a c++ Win32 Desktop app?