【发布时间】:2015-08-19 20:44:49
【问题描述】:
此 Toast 通知在 XE8 和 Windows 10 的桌面上运行良好,但我不知道如何在通知中添加文本行。显示 iTitle 但不显示 iMessage。这对我来说是全新的,所以我不知道该追求哪个方向。
第五次修改......
Remy 出色的 show toast 程序是对原始 Embaracdero 代码的一大改进,但我认为 Remy 并未实际测试过代码,因为它不会按照编写的方式编译。我必须将 TWindowString 更改为 TWindowsString 并将 IXmlNode 更改为 Xml_Dom_IXmlNode 才能编译。
以下内容实际上可以编译,但会在 GetActivationFactory 函数中产生访问冲突。
如果我们能让它正确运行,这将是对原始 Embarcadero 代码的一大改进,并且应该对其他开发人员有价值。
procedure TForm1.ShowToast(const AMessage: String; const ATitle: String = '');
{ Send a Toast Notification }
var
LINotificationManagerStatics: IToastNotificationManagerStatics;
LToast: IToastNotification;
LToastFactory: IToastNotificationFactory;
LToastNotifier: IToastNotifier;
LToastTemplateType: ToastTemplateType;
LAccepted: TAcceptedEventHandler;
LXMLTemplate: Xml_Dom_IXmlDocument;
iTextNode: Xml_Dom_IXmlNode;
LTextNodeList: Xml_Dom_IXmlNodeList;
function GetActivationFactory(const ClassId: String; const Iid: String): IInspectable;
begin
OleCheck(RoGetActivationFactory(TWindowsString(ClassId), TGUID.Create(Iid), Result));
// This produces an access violation at run time
end;
begin
LINotificationManagerStatics := GetActivationFactory(SToastNotificationManager, '{50AC103F-D235-4598-BBEF-98FE4D1A3AD4}') as IToastNotificationManagerStatics;
LToastNotifier := LINotificationManagerStatics.CreateToastNotifier(TWindowsString(Edit1.Text));
if ATitle <> '' then begin
LToastTemplateType := ToastTemplateType.ToastText02;
end else begin
LToastTemplateType := ToastTemplateType.ToastText01;
end;
LXMLTemplate := LINotificationManagerStatics.GetTemplateContent(LToastTemplateType);
LTextNodeList := LXMLTemplate.getElementsByTagName(TWindowsString('text'));
if ATitle <> '' then
begin
LTextNodeList.Item(0).AppendChild(LXMLTemplate.CreateTextNode(TWindowsString(ATitle)) as Xml_Dom_IXmlNode);
iTextNode := LTextNodeList.Item(1);
end else begin
iTextNode := LTextNodeList.Item(0);
end;
iTextNode.AppendChild(LXMLTemplate.CreateTextNode(TWindowsString(AMessage)) as Xml_Dom_IXmlNode);
LToastFactory := GetActivationFactory(SToastNotification, '{04124B20-82C6-4229-B109-FD9ED4662B53}') as IToastNotificationFactory;
LToast := LToastFactory.CreateToastNotification(LXMLTemplate);
LAccepted := TAcceptedEventHandler.Create;
LToast.add_Activated(LAccepted);
LToastNotifier.Show(LToast);
end;
【问题讨论】:
标签: delphi delphi-xe8