CONTENT MOVED: Quickstart: Handling toast activations from Win32 apps in Windows 10
Content moved
Please see the article on docs.microsoft.com for the latest documentation.
Comments
Anonymous
November 02, 2015
As per this article, After Adding the COM server to my Win32 app, the toast is being persisted in Action center. But on tapping the toast either my App's or COM server's (NotificationActivator) Activate method is not being triggered. I am using DOM XML API to display the toast as per the Win32 C++ sample: code.msdn.microsoft.com/.../sending-toast-notifications-71e230a2 I am not using any WinRT API in my Win32 app to display the toast notification. To register COm object when my App starts, I tried to call RegisterObjects() method as described in this article. But there is no RegisterObjects() method provided by MicroSoft::WRL::Module class. Instead I have used Module<InProc>::GetModule().RegisterCOMObject(...) method to register the COM object. Please suggest if something i have missed.Anonymous
November 03, 2015
After adding the COM server to my Win32 app, the toast is persisted in Action center. But My Win32 application is being launched for every few minutes even though there is no user interaction with the toast in Action center. Is it expected behaviour?Anonymous
November 09, 2015
Any update on my previous queries? Please let me know if you need any details from me.Anonymous
November 10, 2015
@Kiran - I've told Lei to follow up, he'll look into this when he has a chance.Anonymous
November 19, 2015
@Lei: Could you Please confirm whether it is usage problem or a bug in APIs?Anonymous
November 20, 2015
Kiran, can you provide the actual code of your COM server, and actual code snippets of how you're registering the COM server? Lei's working on asking whether anyone knows of issues like you mentioned (we are only experts at the normal WinRT API's but we'll attempt to help). It would help us solve your problem if we could see your actual code. You can post code on GitHub GIST and link it here.Anonymous
November 30, 2015
Is there actual code available in GitHub? I modified DesktopToastsSample project, but could not make it works.Anonymous
December 01, 2015
@andrewbares7: As I am unable to upload the complete zip file of my COM Server sample, I have posted few files of COM server and Desktop toast app implementation. The GitHub GIST link for the same is: gist.github.com/.../512f658da1847044a7b6 Please suggest if anything missed.Anonymous
December 07, 2015
@andrewbares7: Any update on my last post?Anonymous
December 09, 2015
This issue has become a blocker for my project work. Today I have observed following behaviour with WRL COM based toast notifications from Desktop Application:
- When I dismiss the Toast notification (The user dismissed the toast notification) from Notification area, the toast notification is pushed into Action center and it is persisted there. But the Activate event handler is not triggered when we tap on the notification inside Action center even though my app is still running. This behaviour is seen without adding any COM server to my desktop app.
- When the Toast is dismissed after time out (TimedOut) then the toast is not persisting in Action center. Atleast it should be persisted in Action center untill the app is running in backgroud. Why it is behaving differently in each dismissal case?
Anonymous
December 17, 2015
Hello, what is the type of variables DocumentIO and factory?Anonymous
December 20, 2015
Thanks for your sample code! By doing some tests, DesktopToastsSample.exe could be launched after clicking the toast notification, but the exported interface Activate seems not called. Do you have the same issue? Is there anything I missed?Anonymous
December 21, 2015
Yes. I am having the same issue that you observed.Anonymous
December 22, 2015
The comment has been removedAnonymous
December 22, 2015
Hi, Kiran I fixed the issue and make DesktopToastsSample.exe works. The issue was caused by without calling Module<OutOfProc>::GetModule().UnregisterObjects();. I post my source code in gist.github.com/.../8701312744f94bcd8701Anonymous
December 22, 2015
Hi, Kiran Sorry, I forgot to mention that if you using Windows 10 SDK, the idl for interface INotificationActivationCallback is not necessary. The interface is available in %Win10SDK_Path%IncludeumNotificationActivationCallback.h.Anonymous
December 22, 2015
@Calvin Lin: Thanks for sharing sample code. From your sample, hr = xmlDocument->LoadXml(toastXML.Get()); is always returning "XML_E_BADSTARTNAMECHAR" (0xC00CE504) error code for me. What could be the problem?Anonymous
December 23, 2015
@Kiran Do you compile the sample program with Win 10 SDK? The format of the toast in my DesktopToastsSample is for adaptive toast which is new of Windows 10. I compiled the sample program with Win 10 SDK. Maybe it could be the root cause. Or You could try the original sample code to launch toast.Anonymous
December 27, 2015
@Calvin Lin, I tried with the original sample code to launch the toast. And I made the changes to the sample code as per your sample except the CreateToastXML method. Still on tapping the toast, CToastActivator::Activate is not called for me.Anonymous
December 28, 2015
@Kiran, By testing my sample, I found the COM server was not stable. Sometimes, the COM server got crashed when action center tried to call CToastActivator::Activate. I still try to find out the root cause. You could check application event log and system event log. Here are the steps how I verified the problem:
- Trigger a toast by DesktopToastsSample.exe - Verify whether the title of toast content in Action Center is APP ID or shortcut link name - If the title display APP ID, that means the created short is not correct
- Check task manager whether DesktopToastsSample.exe was launched after clicking the toast - If the register key for the COM server was not created correctly, DesktopToastsSample.exe will not be launched
- If there was not response after clicking the toast, I will check Windows event logs. I added some logs by OutputDebugString and used DbgView to check the debug logs to trace the problem too.
Anonymous
December 28, 2015
The comment has been removedAnonymous
December 29, 2015
@Calvin Lin, The CToastActivate::Activate() is called when I tap on the Toast notification. But it is not called when I click on the foreground action button (Adaptive toast) on the Toast notification. Is there any other Activate override function to handle the actions? And When i try to Activate the instance of ToastNotificationHistory as: ComPtr<ABI::Windows::UI::Notifications::IToastNotificationHistory> history; HRESULT hr = Windows::Foundation::ActivateInstance(StringReferenceWrapper(RunTimeClass_Windows_UI_notifications_ToastNotificationHistory).Get(), &history); It is returning HRESULT error as "REGDB_E_CLASSNOTREG". How can i use ToastNotificationHistory in desktop app?Anonymous
February 03, 2016
I have really hard time understanding why this toast system had to be made so complex. I mean look at the simplicity of: int WINAPI MessageBox( In_opt HWND hWnd, In_opt LPCTSTR lpText, In_opt LPCTSTR lpCaption, In UINT uType ); compared to this toast monstrosity. Over-engineered APIs like this are the reason for software bloat. Also what's with the application shortcut? Why should a UI message have anything to do with a shortcut file? Why couldn't there be just a registry entry somewhere where to append your application identifier and CLSID? Could you even please bother to provide some rich code examples how to initialize and run the COM server within a dynamic link library or an executable? These small code snippets are hard to understand.Anonymous
February 17, 2016
Could you please upload the entire code for this? Thanks.Anonymous
February 19, 2016
Is the SupressPopup functionality available in C++? Also, could you please give working example of put_ExpirationTime? I can't figure out the parameter type for this function.Anonymous
February 19, 2016
Can someone post a complete, working code sample somewhere. ThanksAnonymous
February 23, 2016
So if I understood correctly, nobody can make it work in c++? We're stuck with .NET/cs?Anonymous
February 24, 2016
Can someone please post an entire Visual Studio solution? Even if it doesn't work, it'd be better than this. I can't get these bits and pieces from here, github, and pastebin to compile. ThanksAnonymous
February 24, 2016
Martin, you have a .NET/C# solution that works? Please post it. Preferably a complete, ready to compile, sample.Anonymous
February 25, 2016
No I don't. I thought there was, but apparently there isn't ... There's only universal app working examples. But that's very restrictive...Anonymous
February 26, 2016
BTW, commenting "if (nRefCount == 0) delete this;" is stupid. Who removes deletes? Maybe changing m_nRefCount = 0; to m_nRefCount = 1; would be better?Anonymous
March 07, 2016
I'm getting an assertion failure on this: Module<OutOfProc>::GetModule().RegisterObjects(); more precisely: Module<OutOfProc>::GetModule() I'm working with Calvin Lin's code sample. Any Ideas?Anonymous
March 08, 2016
Hello , who do that on c# , and thank youAnonymous
March 14, 2016
The Activated event is missing UserInput, while INotificationActivationCallback::Activate method does have the user input data, but only works with string args defined in the notification's XML. In real life, notifications are fired by various modules which attach complex objects to the notification, that they expect the be used once the user clicks the toast. This is impossible to do with just string args. It would have been possible with UserInput in the Activated event, but it's missing. The INotificationActivationCallback::Activate method, with all its ActionCenter and dead application features is useless for the everyday purpose when we just need to implement functionality on a live toast. Also, why is there an IToastNotificationActionTriggerDetail interface in 10.0.10586.0 sdk and no documentation available online for Win32 apps? Why doesn't the IInspectable argument of Activated implement this interface?Anonymous
April 04, 2016
Hi guys, sincerely apologize for missing a full sample and ignoring some of the comments previously - the feature was shipped by a different team and due to preparation for some work in the upcoming Windows update and Build 2016, publishing the sample was delayed. The sample that works e2e is now published on GitHub here:https://github.com/WindowsNotifications/desktop-toasts Please follow up with questions and thanks again.- Anonymous
April 05, 2016
Thank you! The code in RegisterActivator()/UnregisterActivator() fixed a very troubling bug! - Anonymous
April 05, 2016
Did you forget to include notificationactivationcallback.h? Also, regarding your comment "When the user clicks or taps on the toast, the registered COM object is activated, and the Activated event is raised. There is no guarantee which will happen first. If the COM object is activated first, then this message may not show." From my experiments, I noticed that INotificationActivationCallback::Activate always occurs before the Activated handler (added via add_Activated). Activated gives much more possibilities than INotificationActivationCallback::Activate, but lacks the UserInput. Do you think that we will have a guarantee in the future about how these two handlers will be called? - Anonymous
April 05, 2016
Thanks for the sample, it helps a lot, but there seems to be a file missing in the cpp example (#include "notificationactivationcallback.h") - Anonymous
June 15, 2016
This blog post was absolutely critical to extend and understand how to make a winforms legacy application can use the action center and toast notifications locally on a PC so thank you. However, I have some basic questions:1. Is it possible to use the method here (which I have working) to extend to push notifications via WNS or do you need to rewrite the whole application (to UWP) or wait for Project Centennial (my company does not favor either of those methods). Not having a path to use WNS for legacy applications is inconvenient.2. The methods noted here, don't seem to extend to tile updates we try to do locally, just toast notifications and action center? At least its not working for me... (this again appears to be tied to the manifest definitions a full UWP app has for tiles)- Anonymous
January 12, 2017
Thank you Mark, unfortunately, you will need UWP or Centennial to use WNS push service as well as adding live tiles. Could you elaborate on why your company doesn't favor the Centennial approach?
- Anonymous
- Anonymous
Anonymous
April 15, 2016
When the number of notifications in Action Center exceeds 20, I get an extra notification saying “More notifications”. If I click on it, my app opens and all the other 20 toasts from Action Center disappear. I wasn’t able to find any documentation on this. Can you please tell me if this is expected behavior?- Anonymous
January 12, 2017
Hi Elena,This is expected behavior. We automatically add a generic notification that says "more notification" when you have more than 20 notifications. It pretty much sends a message to the user that "there is a more notifications you missed than we can display here so please go into the app and find out what you missed". Can you tell me if you expect to see this happen a lot for users using your app?- Anonymous
January 20, 2017
The comment has been removed
- Anonymous
- Anonymous
Anonymous
September 07, 2016
In a messaging app each time a new message comes in chat I show toast notification and hold pointers to all IToastNotifications shown.When the user clicks the notification the chat is opened. He also can open it by himself. Also this chat can be marked as read from a different device.If any of those three events occur all the notifications from that chat are removed using IToastNotifier::Hide method. So I have some questions:1. If the app gets relaunched there is no way to enumerate the notifications for hiding all of them related to a specific chat - user should have to deal with all the notifications that were left in the action center manually? Will they at least hide from the action center using IToastNotifier::Hide before the app was closed, but after the notification went from screen to the action center? 2. Starting with Windows 10 anniversary update I get reports and logs, that IToastNotifier::Hide sometimes takes up to two minutes (!) before returning. Also I got one debug dump where a call to IToastNotifier::Hide resulted in an inside call to Activated event handler of some (other or the one that I was hiding, I'm not sure) IToastNotification.Is this a valid and correct way to work with the notifications? Why IToastNotifier::Hide takes sometimes so huge amount of time (the app freezes) and sometimes calls the Activated and maybe other handlers inside itself? What is the right way to deal with it? Is there a way to hide the notifications from my app that went to the action center already?- Anonymous
October 28, 2016
>Starting with Windows 10 anniversary update I get reports and logs, that IToastNotifier::Hide sometimes takes up to two minutes (!) before returning. The same problems have occurred in multiple Win10 anniv PCs that use my software.My software name is "IP Messenger for Win" that is open source software.And my user send to me a detail-log and it indicates... 1. create IToastNotifier 2. call IToastNotifier::Show() (1sec - 5sec later) 3. call IToastNotifier::Hide() 4. release IToastNotifierIt is okay to run this combination several times.But it runs many times(10-20times) with few timing gap, IToastNotifier::Hide() spends just 120sec.If it occurs, Hide() always spends 120sec.- Anonymous
October 31, 2016
I confirmed the Hide() freeze problem can be avoided by using multi-thread & COM(MTA=COINIT_MULTITHREADED).(I think it is a Win10 Anniv. bug, so the following way is only a workaround.)If you want to create a new toast,1. create a new thread and CoInitialize(NULL, COINIT_MULTITHREADED);2. create a toast and relative object(factory/event etc) in this toast thread.(1 new toast = 1 new thread...it is a very rich way. I don't like it, but I think there is no other way to avoid it...)If you want to hide this toast in main/other thread,3. send/notify a hide-request to this toast thread. (in some way)4. Call Hide() in this toast thread.Note.5. In MTA mode, Click or Timeout event are issued by NOT this toat(and main) thread. (It is WinRT/COM internal thread?)Bye the way, strangely, using multi-thread with MTA, it seems Hide() becomes not to freeze in this toast thread (not only main/other thread).So I doubt this problem is relative to WinRT/COM(STA=COINIT_APARTMENTTHREADED) synchronize mechanism.- Anonymous
January 26, 2017
Still no other workaround found? My users are still complaining, I had to disable Windows toast notifications by default in my software (use custom self made notifications by default).I'm afraid to spawn a thread for each notification, if they start to leak because for some reason none of the callbacks get called or smth like that it will be very bad.leixu2046 perhaps you do have some thoughts / reports / information? This is a rare (I cannot reproduce that myself) but regularly seen and very bad behaviour, I have several issues on github.
- Anonymous
- Anonymous
- Anonymous
Anonymous
November 23, 2016
I see that up on GitHub, there is a fully working version of this in C# but the C++ DesktopToastsSample still uses the old Template model. Is there a FULL working version in C++ anywhere? Also, I would prefer not to have to hook into ActionCenter. All I really want to do is to use the new GenericTemplate TemplateType to create a more specific type of toast. The only action I need users to do is to click on the toast to acknowledge it.- Anonymous
March 09, 2018
Hi Maria, the C++ code sample has been updated to fully utilize interactive toasts and ToastGeneric! See it on GitHub: https://github.com/WindowsNotifications/desktop-toastsAdditionally, the documentation has been fully re-written and improved: https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/send-local-toast-desktop-cpp-wrlLet us know if you have any further questions! Thanks!
- Anonymous
Anonymous
December 30, 2016
Who's giving these posts 5 star ratings? This doesn't even work.Anonymous
January 20, 2017
Hi, I'd like to know if there's a way for my app to be notified when the user sets the Notifications (either Global or per app) to Off from Windows Settings . Thanks!Anonymous
July 17, 2017
The activation doesn't work if the app is running as administrator.Anonymous
September 01, 2017
I have exactly same problem as AYCohen. Everything works perfectly fine from user and from Administrator Toasts are not activated.Does anyone have a solution for this problem ?Anonymous
November 22, 2017
Hi,I´m currently developing an extensions (DLL) for a third party desktop application. Therefore i do not have a standalone application (.EXE).How can i make my ToastNotifications be persistent without having to register the COM server in a seperate non-UI process.Thanks!Anonymous
November 28, 2017
Hi leixu2046,I want to implement desktop-toasts with progressbar.I have seen many sample codes of deskop app on GITHUB and offical web, but I cannot find the ignore code with "..." in In "Sending and handling interactive toast notifications" section.For C++ language, how to initializa "IXmlDoxcumentIO" variables? Other words,how I load xml file to IXmlDocument? ThanksThis is my code : /************ start ******/HStringReference toastXML( L"" L"" L"" L"Downloading this week's new music..." L"" L"" L"" L""); ComPtr DocumentIO ;//throw exception,becacust I don't know how to initializa "IXmlDoxcumentIO" variableshr = DocumentIO->LoadXml(toastXML.Get());ComPtr xml;// is this load xml file to IXmlDocument?DocumentIO.CopyTo(toastXml.GetAddressOf());... ComPtr toast;hr = factory->CreateToastNotification(xml, &toast); ... hr = notifier->Show(toast.Get());/ end ******************/- Anonymous
March 09, 2018
The comment has been removed
- Anonymous