Microsoft and The Smith Family via the #WeSpeakCode Program Delivers Coding to Students at Mitchell High School on Windows 10 as part of #UpgradeYourWold Campaign

Microsoft and The Smith Family via the #WeSpeakCode Program Delivers Coding to Students at Mitchell High School on Windows 10 as part of #UpgradeYourWold Campaign

Yesterday I had the privilege of being involved in the delivery of introductory computer science and programming material to year 10 and 11 students out at Mitchell High School in Blacktown. The material was from http://studio.code.org which has a fantastic repository of material for high school students (specifically https://studio.code.org/s/20-hour which is the course we were delivering).

This program was a combined initiative from The Smith Family and Microsoft and the first day (yesterday) aligned with the release of Windows 10. It was fantastic to see the energy in the room and the excitement from the students as they played and explored all the new features of Windows 10.

It was also great to see the media pick up what a great experience this was:

http://www.smh.com.au/national/education/sydney-school-students-get-a-taste-of-careers-in-computing-and-agriculture-20150729-gimzax.html

http://www.theaustralian.com.au/business/technology/windows-10-australian-students-pass-their-verdict/story-e6frgakx-1227461837728

Launching Windows Store Applications from Code in Windows 10

Launching Windows Store Applications from Code in Windows 10

On Windows 8/8.1 after installing an application from the Windows Store it was possible to interrogate the registry and find the AppUserModelId which could then be used to launch the application. This process is described in more detail here – http://www.codeproject.com/Articles/542316/Run-Windows-Store-Apps-From-Desktop.

There are a couple of ways to launch the application using the AppUserModelId:

– The first (as the link suggests) is to use the launcher utility that comes with the SDK eg:
C:Program Files (x86)Windows Kits8.0App Certification KitMicrosoft.Windows.SoftwareLogo.AppxLauncher.exe “AppUserModelId

– The other way is to use the ApplicationActivationManager (https://msdn.microsoft.com/en-us/library/windows/desktop/hh706902(v=vs.85).aspx) which can be used as follows:

uint pid;
var mgr = new ApplicationActivationManager();
mgr.ActivateApplication(“[AppUserModelId]”, null, ActivateOptions.None, out pid);

This technique relies on getting the AppUserModelId from the following Registry:

HKEY_CURRENT_USERSoftwareClassesActivatableClassesPackage**PackageFullName**Server

The installation process for Store applications on Windows 10 doesn’t create this Registry key, which means we need another way to determine the AppUserModelId. I haven’t found a definitive way to do this but I did manage to find a way which seems to work. Essentially you need to append “!App” to the package family name of your application (not the package full name).

If you haven’t played around with the powershell commands for installing and querying installed packages, it’s worth taking a look. For example to get a list of all packages for a particular publisher you can issue the following powershell command:

get-appxpackage -publisher “OID.0.9.2342.19200300.100.1.1=6434210, CN=Built to Roam Pty Ltd, OU=Built to Roam Pty Ltd”

This will return a listing for each application such as the following:

Which, as you can see contains the PackageFamilyName – add “!App” and you have a string that should work as the AppUserModelId, allowing you to launch the application from code.

Visual Studio 2015 RTM and the case of the missing Microsoft Advertising SDK for Windows 8.1

Visual Studio 2015 RTM and the case of the missing Microsoft Advertising SDK for Windows 8.1

I just got around to upgrading to VS2015 RTM having run the RC since it was available (just as an aside VS2015 has been the only version of Visual Studio that I’ve been running for quite some time now). And as Murphy’s law goes, the first project I open doesn’t build and run – OMG what pain do I now need to endure?

It appears that someone has made the decision to remove the Windows 8.1 Advertising SDK (perhaps due to the recent sale of MS advertising assets), which means my Windows 8.1 application is now missing a reference.  According to the Ads in Apps website (http://adsinapps.microsoft.com/en-US/sdk) the SDK is installed in VS2013 update 2 or later (clearly not the case)

Luckily, a bit of searching revealed the SDK available via Visual Studio Gallery at https://visualstudiogallery.msdn.microsoft.com/3d3fa204-0641-4317-ab2c-50092f732edb

Windows Phone 8.1, Microsoft Lumia 640XL and the case of the Virtual Hardware Buttons

Windows Phone 8.1, Microsoft Lumia 640XL and the case of the Virtual Hardware Buttons

The Microsoft Lumia 640 and 640XL were one of the first Windows Phone devices to take advantage of the move to on-screen hardware buttons. Rather than the traditional hardware buttons for Back, Start and Search, these devices have software rendered buttons (note that there were previous devices that had the buttons as part of the same glass as the reset of the screen but this isn’t the same as having them rendered in software). There were some that didn’t like this move (eg http://www.7tutorials.com/reviewing-microsoft-lumia-640-xl-good-smartphone-business-users) but an nice effect of them being software is that they can be dismissed off the screen. This means that the buttons can be swiped away, leaving more screen available for applications.

The unfortunately thing about this is that because this feature shipped as an update to Windows Phone 8.1 there isn’t good support for detecting when the available screen size changes, often leaving applications either with controls rendered under the buttons, or with empty screen space under the content of the application (where the buttons used to reside).

Side note: Rudy Huyn in his post, “How to test my app on phone with navigation bar and why it matters,” covers how to use the Windows Phone emulator to test applications for this behaviour.

I spent a bit of time this afternoon trying to work out a workable solution to this. The result was a bit hit and miss but the following seems to work:

In order to take advantage of the full screen I added the following lines to the end of the OnLaunched method in the App.xaml.cs file:

var applicationView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView();
applicationView.SetDesiredBoundsMode(Windows.UI.ViewManagement.ApplicationViewBoundsMode.UseCoreWindow);

The UX of the screen is very basic – it has a background color so that you can see where the page is being rendered and a textbox at the bottom of the screen so that you can see whether an element has been hidden. Note also that the VerticalAlignment of the page is set to Top. This might seem weird but if you don’t, as you adjust the Height of the page in accordance with the visible bounds, you’ll see the page rendered in the middle of the screen, which is not what you want.

<Page x_Class=”AppBarTest.MainPage”
      http://schemas.microsoft.com/winfx/2006/xaml/presentation”>http://schemas.microsoft.com/winfx/2006/xaml/presentation
      http://schemas.microsoft.com/winfx/2006/xaml”>http://schemas.microsoft.com/winfx/2006/xaml
      VerticalAlignment=”Top”>
    <Page.BottomAppBar>
        <CommandBar>
            <AppBarButton Icon=”Accept”
                          Label=”appbarbutton” />
            <AppBarButton Icon=”Cancel”
                          Label=”appbarbutton” />
        </CommandBar>
    </Page.BottomAppBar>

    <Grid Background=”LightBlue”>
        <TextBox Text=”Testing”
                 VerticalAlignment=”Bottom”
                 Margin=”0″ />
    </Grid>
</Page>

The code for this page is where all the hacking happens – essentially it looks to determine how tall the page should be based on the space occluded by the status bar and the input pane. The trick is to make sure this is called anytime something adjusts the visible bounds available to the app.

public sealed partial class MainPage
{
    public MainPage()
    {
        InitializeComponent();
           
        var appView = ApplicationView.GetForCurrentView();
        appView.VisibleBoundsChanged += VisibleBoundsChanged;
    }

    private void VisibleBoundsChanged(ApplicationView sender, object args)
    {
        ResizeMe();
    }

    private void ResizeMe()
    {
        var statusBar = StatusBar.GetForCurrentView();

        var appView = ApplicationView.GetForCurrentView();
        var input = InputPane.GetForCurrentView();
        var newHeight = appView.VisibleBounds.Height + (statusBar?.OccludedRect.Height) ??
                                0 + (input?.OccludedRect.Height) ?? 0;
        if ((input?.OccludedRect.Height ?? 0) <= 0 || newHeight <
this.Height)
        {
            this.Height = newHeight;
        }
    }

Update: You should also attach an event handler to the Got and Lost focus on the TextBox and invoke ResizeMe otherwise there are some scenarios where the TextBox ends up under the virtual buttons