The WinRT API headers for Delphi are now on GetIt and here is a demo to try out using Windows 10 notifications in a VCL Win32 application.

Windows 10 Webinar

Yesterday, we had a Windows 10 focused webinar, with a Microsoft guest and a few of us (me, David I, Jim McKeeth, and JT) talking about Windows 10 and the support RAD Studio XE8 offers for the coming versions of Windows. If you missed it, the replay will soon be available. What I showed in the webinar, beside some classic demos, was a VCL application using notifications on Windows 10, a feature not available in the traditional Win32 APIs but only using the new WinRT APIs.

How to do you get the headers for that API and how do you get a working demo? Keep reading...

Delphi WinRT Headers for Windows 10 on GetIt

First of all, today we made available the headers for the WinRT API on GetIt, to all developers with Delphi or RAD Studio XE8 (there is no direct support for C++, at this very moment). Just open GetIt in XE8 and click on the corresponding entry, shown below.

Notice that this code is for the Windows 10 preview, it is likely that the APIs and our header translations will change over the coming months. So you might have to change/clean up your code in the future, but it is great to be able to start target WinRT classes today with XE8.

The WinRT Notification Demo

As an example of an interesting feature you can use only from WinRT, this demo is focused on the new notifications, called "toast" notifications. Now, the API is available but not really encapsulated in ready-to-use components, so the code is far from simple and I won't list everything here, only the core elements. This is what we want to obtain:

This is a portion of the code used to create a notification. As you can guess below, WinRT classes are basically used like COM objects, and they share the core architecture. The objects creation doesn't use a CoClass (or class factory) but is a little more complex:

    if Succeeded(RoGetActivationFactory(LString, TGUID.Create('{50AC103F-D235-4598-BBEF-98FE4D1A3AD4}'), LCreated)) then
      LINotificationManagerStatics := LCreated as IToastNotificationManagerStatics;
      if Succeeded(WindowsCreateString(PWideChar(Edit1.Text), Length(Edit1.Text), LString2)) then
        LToastNotifier := LINotificationManagerStatics.CreateToastNotifier(LString2);
        LXMLTemplate := LINotificationManagerStatics.GetTemplateContent(ToastTemplateType.ToastText02);
        if Succeeded(WindowsCreateString(PWideChar(SToastNotification), Length(SToastNotification), LString)) then
          if Succeeded(RoGetActivationFactory(LString, TGUID.Create('{04124B20-82C6-4229-B109-FD9ED4662B53}'), LCreated)) then
          LToastFactory := LCreated as IToastNotificationFactory;
          LToast := LToastFactory.CreateToastNotification(LXMLTemplate);
          LAccepted := TAcceptedEventHandler.Create;
The TAcceptedEventHandler class is the one that has an invoke callback method, that logs in the memo the fact taht the information was accepted (the dismiss portion I'll have to refine). This is the code:
procedure TAcceptedEventHandler.Invoke(sender: IToastNotification; args: IInspectable);
  Form51.Memo1.Lines.Add ('You clicked on the notification!');
I know the reference to the global form is ugly, but the code is complex enough to avoid the extra indirection. Do you want to give it a go? You can download the complete demo at I'm probably going to update it, and possibly also write a couple more examples, covering other new areas in WinRT. 

Windows 10 is Coming

...and it looks it will be a very important version of Windows, so get the Windows 10 Preview now, and start using XE8 to experiment the integration of your VCL (and FireMonkey) applications with it.