On the official website of delphi http://docwiki.embarcadero.com/CodeExamples/Tokyo/en/VCL.Windows_10_Notifications_Sample I see an example of how notifications work. Everything is working. BUT this is a pretty simple example. As far as I know, the windows API allows much more features: with a picture, with buttons, pending, and so on ... here it shows: https://blogs.msdn.microsoft.com/ti_and_toasts/2015/07/08/toast -notification-and-action-center-overview-for-windows-10 /

Tell me how to do it all?

  • The list of opportunities for each platform: Using Notifications - moreover, these are all possibilities. Not yet implemented. You can always open the TNotification class ( System.Notification.pas ) and recalculate the available options. - zed
  • Well, but how can you implement advanced notifications can you advise? - Alex Lizenberg
  • @zed if editorial Delphie comes with source code. in the starter version only dcu should be - teran
  • one
    use third-party components, or work directly with the interfaces provided by the OS, if the native components delfe do not provide this feature. - teran
  • tell me what else there are third-party components - Alex Lizenberg

1 answer 1

In general, figured out the notifications, it turned out that the built-in library in Delphi Tnotification - allows you only to try notifications using a simple example, otherwise I had to figure it out with the help of microsoft documentation. But I still have not fully figured out how to get a reaction to events. How to make complex notifications (with pictures and buttons) I figured out.

It seemed to me that the component, which in Delphi, rather complicates the understanding of how the notification works. Actually, windows 10 notification is actually an XML document.

Here is the basic template:

 <toast> <visual> <binding template="ToastGeneric"> Ρ‚ΡƒΡ‚ ΡƒΠΊΠ°Π·Ρ‹Π²Π°Π΅ΠΌ тСкст ΠΈ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ </binding> </visual> <actions> Ρ‚ΡƒΡ‚ ΡƒΠΊΠ°Π·Ρ‹Π²Π°Π΅ΠΌ ΠΊΠ½ΠΎΠΏΠΊΠΈ </actions> </toast> 

As I achieved, I first wanted to find, so to speak, clean code, purely on winapi, in order to simply form my document and transmit directly, but I could not get this code to work:

https://stackoverflow.com/questions/32105337/how-to-add-a-text-node-to-a-toast-notification

Then I copied the source code of the component in the project folder and began to correct the functions I needed, because if I changed the component in the source folder - the changes did not work ...

As I did: I create the XML I need myself and pass it to the notification component, for this I changed the function in the component to accept my code

 class function TToastTemplateGenerator.GetXMLDoc(const ANotification : TNotification): Xml_Dom_IXmlDocument; // ... begin // LTemplateType := SelectTemplate; Result := ANotification.Template; // Result := TToastNotificationManager.Statics.GetTemplateContent(ToastTemplateType.ToastText01); // ΠΎΡΡ‚Π°Π»ΡŒΠ½ΠΎΠΉ ΠΊΠΎΠ΄ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ ΠΌΠΎΠΆΠ½ΠΎ Π·Π°ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚ΠΈΡ‚ΡŒ 

Well, in the notification class, I added a field with a template

  TNotification = class(TPersistent) // ... Title: string; Template: Xml_Dom_IXmlDocument; 

Well, now my notification call function looks like this:

 procedure TForm1.Button1Click(Sender: TObject); var MyNotification: TNotification; //Defines a TNotification variable XML: String; hXML: HString; begin XML := '<toast activationType="protocol" launch="https://www.alta.ru" duration="short">' + '<visual> ' + ' <binding template="ToastGeneric"> ' + ' <image placement="appLogoOverride" hint-crop="circle" src="file:///d:\downloads\alta.jpg"/> ' + ' <text hint-maxLines="1">Adaptive Tiles Meeting</text> ' + ' <text>Conf Room 2001 / Building 135</text> ' + ' <text>10:00 AM - 10:30 AM</text> ' + ' <image src="file:///d:\downloads\ketrin.jpg"/> ' + ' </binding> ' + '</visual> ' + ' <actions> ' + ' <action content="Open Google" activationType="protocol" arguments="http://www.google.com"/> ' + ' <action content="Open 2" activationType="protocol" arguments="http://yandex.ru"/> ' + '</actions> ' + '</toast>' ; MyNotification := NotificationCenter1. CreateNotification; //Creates the notification try MyNotification.Name := 'Windows10Notification'; //Defines the name of the notification. MyNotification.Template := str_to_XML (XML); NotificationCenter1.PresentNotification(MyNotification); //Presents the notification on the screen. finally MyNotification.Free; //Frees the variable end; end; 

secondary functions

 function HStr(Value: String): HString; begin if NOT Succeeded(WindowsCreateString(PWideChar(Value), Length(Value), Result)) then raise Exception.CreateFmt('Unable to create HString for %s', [Value]); end; function str_to_XML(Const XML: String): Xml_Dom_IXmlDocument; var hXML: HString; begin Result := TToastNotificationManager.Statics.GetTemplateContent(ToastTemplateType.ToastText01); hXML := HStr(XML); try (Result as Xml_Dom_IXmlDocumentIO).LoadXml(hXML); finally WindowsDeleteString(hXML); end; end; 

With the response to the click, I'm trying to sort out this issue Reaction to the actions of the windows 10 notifications on delphi , looking for a solution. How to find sure to tell