Windows 10 Notifications from a VCL app with the WinRT API

絕刀狂花
发布: 2025-08-31 08:40:01
原创
653人浏览过

the winrt api headers for delphi are now available on getit, and you can explore a demo showcasing the use of windows 10 notifications in a vcl win32 application.


The WinRT API headers for Delphi are now accessible on GetIt, providing you with a demo to explore the use of Windows 10 notifications within a VCL Win32 application.

We recently conducted a Windows 10 focused webinar, featuring a Microsoft guest alongside a few of us (myself, David I, Jim McKeeth, and JT) discussing Windows 10 and the capabilities RAD Studio XE8 offers for upcoming Windows versions. If you missed the event, the replay will be available soon. During the webinar, apart from classic demos, I demonstrated a VCL application utilizing Windows 10 notifications, a feature not supported by traditional Win32 APIs but accessible through the new WinRT APIs.

Interested in obtaining the headers for this API and running a working demo? Continue reading to find out how...

The WinRT API headers for Windows 10 are now available on GetIt for all developers using Delphi or RAD Studio XE8 (note that there is currently no direct support for C++). Simply access GetIt in XE8 and select the relevant entry as shown below.

Windows 10 Notifications from a VCL app with the WinRT APIPlease be aware that this code targets the Windows 10 preview, and both the APIs and our header translations may evolve in the coming months. You may need to adjust or clean up your code later, but it's advantageous to start working with WinRT classes in XE8 now.

The WinRT Notification Demo offers an example of a unique feature available only through WinRT: "toast" notifications. While the API is accessible, it isn't encapsulated in ready-to-use components, making the code somewhat complex. I'll highlight the core elements rather than listing the entire code. Our goal is to achieve this:

幻舟AI
幻舟AI

专为短片创作者打造的AI创作平台

幻舟AI 279
查看详情 幻舟AI

Windows 10 Notifications from a VCL app with the WinRT APIHere's a snippet of the code used to create a notification. As you can see, WinRT classes function similarly to COM objects, sharing a common architecture. Object creation is more intricate than using a CoClass (or class factory):

if Succeeded(RoGetActivationFactory(LString, TGUID.Create('{50AC103F-D235-4598-BBEF-98FE4D1A3AD4}'), LCreated)) then    begin      LINotificationManagerStatics := LCreated as IToastNotificationManagerStatics;      if Succeeded(WindowsCreateString(PWideChar(Edit1.Text), Length(Edit1.Text), LString2)) then      begin        LToastNotifier := LINotificationManagerStatics.CreateToastNotifier(LString2);        LXMLTemplate := LINotificationManagerStatics.GetTemplateContent(ToastTemplateType.ToastText02);        if Succeeded(WindowsCreateString(PWideChar(SToastNotification), Length(SToastNotification), LString)) then        begin          if Succeeded(RoGetActivationFactory(LString, TGUID.Create('{04124B20-82C6-4229-B109-FD9ED4662B53}'), LCreated)) then          LToastFactory := LCreated as IToastNotificationFactory;          LToast := LToastFactory.CreateToastNotification(LXMLTemplate);          LAccepted := TAcceptedEventHandler.Create;          LToast.add_Activated(LAccepted);          LToastNotifier.Show(LToast);        end;
登录后复制

The TAcceptedEventHandler class includes an invoke callback method that logs the acceptance of the notification in the memo. Here's the code:

procedure TAcceptedEventHandler.Invoke(sender: IToastNotification; args: IInspectable);begin  Form51.Memo1.Lines.Add ('You clicked on the notification!');end; 
登录后复制

I acknowledge that referencing the global form directly might not be ideal, but the complexity of the code justifies avoiding additional indirection. Are you interested in trying this out? You can download the full demo at dl.dropboxusercontent.com/u/133855/WinRTCheck.zip. I plan to update it and potentially create more examples covering other new WinRT features.

Windows 10 is on the horizon, promising to be a significant release. Start exploring the Windows 10 Preview now, and use XE8 to experiment with integrating your VCL (and FireMonkey) applications with it.

以上就是Windows 10 Notifications from a VCL app with the WinRT API的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号