Programming Windows: Hello, WinRT (Premium)

I spent a lot of time trying to figure out a way to run the Windows 8 Developer Preview in a virtual machine so that I could write code using its bundled version of Visual Studio 11 Express and the then-current version of the Windows Runtime (WinRT) APIs. But I needn’t have bothered: as it turns out, a basic Windows 10 Universal Windows Platform (UWP) app created using the most recent version of Visual Studio at the time of this writing---2022---is nearly identical from a software code perspective.

To prove this, I examined the code that Charles Petzold provided for his first, hello world-style Windows 8 app in the book Programming Windows Sixth Edition. And then I compared that code to the code that Visual Studio 2022 generates when you create a new, blank UWP app.

Here’s the Petzold code for MainPage.xaml:
<Page
    x:Class="Hello.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Hello"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006
    mc:Ignorable="d">

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">

    </Grid>
</Page>
And here’s the Visual Studio 2022/UWP code:
<Page
    x:Class="Hello.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Hello"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>

    </Grid>
</Page>
As you can see, the differences are minor: the code that sets the background color has moved from the <Grid> level to the <Page> level, and instead of being a static resource, it’s now a theme resource. But the Windows 8/Petzold code still works if you want to make that change for some reason.

If you run this blank app as-is in Windows 10/11, you will get a floating app window because Microsoft moved past the Windows 8 full-screen app requirement very quickly.

But you can force the app to emulate Windows 8 by adding a single line of code to the app constructor in app.xaml.cs:
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
Now, the app runs full screen as it would have in Windows 8. (Though it remains blank of course.)

Petzold added a TextBlock inside of the Grid in MainPage.xaml to accomplish the “Hello, world!” nature of this simple app:
<TextBlock Text="Hello, Windows 8!"
                   FontFamily="Times New Roman"
                   Font...

Gain unlimited access to Premium articles.

With technology shaping our everyday lives, how could we not dig deeper?

Thurrott Premium delivers an honest and thorough perspective about the technologies we use and rely on everyday. Discover deeper content as a Premium member.

Tagged with

Share post

Please check our Community Guidelines before commenting

Windows Intelligence In Your Inbox

Sign up for our new free newsletter to get three time-saving tips each Friday

"*" indicates required fields

This field is for validation purposes and should be left unchanged.

Thurrott © 2024 Thurrott LLC