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
System.Notification.pas) and recalculate the available options. - zed