Retrieving Windows 8 Theme Colours

See also: Windows 8 Theme Colours Reference.

Windows 8 doesn’t offer developers access to system theme colours, unlike its cousin, Windows Phone. Even for a version 1 product, this seems like a strange omission. Then again, we still don’t have a working public API for retrieving the Aero glass colour (or whatever we call it now that Aero’s gone) 6 years after the release of Windows Vista.

The functions that the system uses to retrieve colours are defined in UxTheme.dll. In particular, we’re interested in GetImmersiveColorSetCount (export #94), GetImmersiveColorFromColorSetEx (export #95), GetImmersiveColorTypeFromName (export #96), GetImmersiveUserColorSetPreference (export #98) and GetImmersiveColorNamedTypeByIndex (export #100). Relying on undocumented functions is a bad idea, and will cause your program to fail certification, so you won’t be able to use them in apps distributed through the Windows Store anyway.

For desktop developers who still want to use these functions, read on. Just assume that they’ll break in future versions of Windows (or even with patches to Windows 8).

Screenshot of Windows 8 Colours

Continue reading “Retrieving Windows 8 Theme Colours”

FastPictureViewer Codec Pack, Windows 8 and WPF don’t play nicely together

Update (2012-09-06): After some trial and error, it seems the Canon Hack Development Kit (CHDK) component is causing the issue. If you’re experiencing the same problem, try removing this component.

Update (2012-09-05): The FastPictureViewer support team was unable to reproduce the issue, but suggested it might have something to do with the JPEG Auto-Rotate feature. I was able to resolve the issue by installing only the following components of the codec pack: Photoshop PSD, Lightroom Previews, Adobe DNG, Canon CR2, CRW, PDF Thumbnails and Control Panel. This suggests one of the other components was causing the conflict on my machines.

I use the FastPictureViewer Codec Pack for viewing DNG images in Windows Explorer, amongst other things. Unfortunately, however, installing version 3.3.0.69 of the codec pack in Windows 8 (64-bit) caused my installations of Visual Studio 2010, Visual Studio 2012, Blend 4 and Blend for Visual Studio 2012 to stop working to various extents. Both versions of Blend crash silently. The start pages in both versions of Visual Studio fail to load, with VS2010 displaying a ‘Content Load Error’ relating to ‘System.Windows.Baml2006.TypeConverterMarkupExtension’ throwing an exception. The error message displayed where the Visual Studio 2012 Solution Explorer belongs was more useful: ‘System.Runtime.InteropServices.COMException: The codec is in the wrong state. (Exception from HRESULT: 0x88982F04)’.

Uninstalling the codec pack caused everything to start working again. I’ll update this post if/when a future release resolves the incompatibility.

Screenshot of Visual Studio 2010 Error

Screenshot of Visual Studio 2012 Error 

Office 2013: Further Evidence of the Demise of ClearType?

Poking around the Office 2013 Customer Preview, one thing that caught my eye immediately was the lack of ClearType font smoothing. Nearly all user interface elements use ‘greyscale’ font smoothing (as opposed to ClearType’s sub-pixel smoothing). I’ve highlighted the parts of Word 2013 that still use ClearType:

Screenshot of ClearType in Microsoft Word 2013Screenshot of ClearType in Microsoft Word 2013

The text in cells in Excel 2013 still respects the system’s ClearType setting, and Outlook 2013 is a real mess (about half-and-half). OneNote 2013 seems to have retained ClearType in most places (outside the ribbon control).

Long Zheng earlier noted the absence of ClearType from the Metro environment and there are several possible reasons for it falling out of favour at Microsoft. Sub-pixel anti-aliasing isn’t necessarily suited to tablets that need to support multiple orientations (unless different sub-pixel orderings are taken into account), and screens with high pixel densities can get away with greyscale font smoothing.

I fear that this is another case of the tablet tail wagging the Microsoft dog – desktop and laptop users of Office 2013 (and Metro-style apps in Windows 8) will have to deal with lower quality text due to the new hardware Microsoft is targeting with its upcoming releases.

The Office 2013 Customer Preview is, of course, just that, and things might change before RTM. Regrettably this wasn’t fixed for the Office 2013 RTM.

WPF: Using System Colours in Animations

WPF provides access to the Windows system colours through the System.Windows.SystemColors class. As the MSDN documentation indicates, it’s possible to bind to these colours dynamically using the *Key resources, so when the system colours change, so will the appearance of your application.

This code will set the colour of a TextBlock to the ‘GrayText’ system colour, and will change automatically if the user switches themes:

In many cases, there’s no reason not to bind dynamically. Problems arise with animations, however. From MSDN:

You can’t use dynamic resource references or data binding expressions to set Storyboard or animation property values. That’s because everything inside a ControlTemplate must be thread-safe, and the timing system must Freeze Storyboard objects to make them thread-safe. A Storyboard cannot be frozen if it or its child timelines contain dynamic resource references or data binding expressions.

This means that you’re stuck using static references to system colours in your animation storyboards – if the user changes the system colours while your application is running, your storyboards won’t update automatically. Worst-case scenario, you might end up with unreadable text.

I don’t think there are any workarounds that don’t involve reloading windows and/or resource dictionaries (depending on where the style code is located). Reloading a window is easy enough – just be careful if you’re closing your application’s last window: the program will shut down if there are no remaining references to any windows.

The method for reloading a resource dictionary is a bit less obvious. It seems that XAML files accessed by their pack URIs are already compiled, so the system colours will be fixed in place once the program starts up. To get around this, change the build action for the XAML file containing the resource dictionary to ‘Embedded Resource’. You can then (re)build the resource dictionary as you please using XamlReader:

Remove the old resource dictionary from your application’s merged resource dictionaries, then add the new one.

Creating a new resource dictionary like this seems to be fairly slow, so try to avoid doing it on a regular basis. To tell when the Windows theme or system colours have changed, you’ll need to listen for the window messages WM_THEMECHANGED and WM_SYSCOLORCHANGE. See this post for information about listening for window messages in WPF.

More on Segoe UI in Windows 8

Note: the following is based on the Windows 8 Release Preview (build 8400) and may not accurately reflect the final version of Windows 8. I’ll update this post if there are changes in future builds.

Updated: The fonts have been updated in the public beta (Windows Consumer Preview) and release candidate (Windows Release Preview) and I’ve changed the tables below to reflect this. I was also made aware of some additional information about changes to Segoe UI, including new stylistic sets and support for ligatures: you can read more at Subacme.

Further to my earlier post about Segoe UI Light in Windows 8, I’ve done some more research into the changes to the Segoe family of fonts. The Fonts class in the .NET Framework was helpful for retrieving information about the fonts.

First off, Segoe Print and Segoe Script and their bold variants have not been modified and are still labelled version 5.02 and 5.00, respectively. All existing variants of Segoe UI have been updated, and there is one new variant: Segoe UI Semilight. The latter is in fact used as the caption and small caption font in Windows 8 – Windows Vista and Windows 7 used Segoe UI (Regular). The Windows Phone 7 platform includes Segoe WP Semilight, and Segoe UI Semilight seems to be a superset of that font.

Apparently new in the Windows 8 Release Preview are three italic variants: Segoe UI Light Italic, Segoe UI Semibold Italic and Segoe UI Semilight Italic.

The following tables summarise the differences in glyph and character counts between the Windows 7 and Windows 8 versions of the Segoe UI font family:

Segoe UI Regular

  Windows 7 Windows 8 Developer Preview Windows 8 Consumer Preview Windows 8 Release Preview
Version 5.01 5.12 5.16 5.24
Glyphs 2899 4281 4490 4516
Characters 2658 3283 3423 3404

Segoe UI Bold

  Windows 7 Windows 8 Developer Preview Windows 8 Consumer Preview Windows 8 Release Preview
Version 5.01 5.12 5.15 5.24
Glyphs 2899 4290 4428 4442
Characters 2658 3283 3421 3401

Segoe UI Italic

  Windows 7 Windows 8 Developer Preview Windows 8 Consumer Preview Windows 8 Release Preview
Version 5.01 5.10 5.15 5.22
Glyphs 2381 2478 2597 3077
Characters 2130 2180 2299 2525

Segoe UI Bold Italic

  Windows 7 Windows 8 Developer Preview Windows 8 Consumer Preview Windows 8 Release Preview
Version 5.01 5.10 5.15 5.22
Glyphs 2381 2478 2597 3077
Characters 2130 2180 2299 2525

Segoe UI Light

  Windows 7 Windows 8 Developer Preview Windows 8 Consumer Preview Windows 8 Release Preview
Version 5.00 5.12 5.15 5.25
Glyphs 2380 4036 4178 4236
Characters 2131 3090 3230 3211

Segoe UI Light Italic

  Windows 8 Release Preview
Version 5.22
Glyphs 3089
Characters 2525

Segoe UI Semibold

  Windows 7 Windows 8 Developer Preview Windows 8 Consumer Preview Windows 8 Release Preview
Version 5.00 5.12 5.16 5.24
Glyphs 2380 4089 4228 4242
Characters 2131 3144 3231 3211

Segoe UI Semibold Italic

  Windows 8 Release Preview
Version 5.22
Glyphs 3089
Characters 2525

Segoe UI Semilight

  Windows 7 Windows 8 Developer Preview Windows 8 Consumer Preview Windows 8 Release Preview
Version N/A 5.12 5.15 5.24
Glyphs N/A 4034 4175 4189
Characters N/A 3090 3230 3210

Segoe UI Semilight Italic

  Windows 8 Release Preview
Version 5.23
Glyphs 3089
Characters 2525

Segoe UI Symbol

  Windows 7 Windows 8 Developer Preview Windows 8 Consumer Preview Windows 8 Release Preview
Version 5.00 5.33 5.46 5.55
Glyphs 3090 5122 6785 6846
Characters 2864 4547 5092 5217

Supported Unicode Blocks

For further information about which Unicode blocks are supported by the Segoe family of fonts, you can download my extended analysis here:

segoe-analysis.7z
2,825 bytes; SHA-1: DFFA40934DB3305054C40AF3FD6E7224F5CF1EFB

Segoe UI Light Improvements in Windows 8

Windows 7 comes with Segoe UI Light version 5.00/0.90. Windows 8 (as of the Windows Consumer Preview) comes with version 5.15, which has been hinted at various sizes. This comes as a very welcome change, especially with Microsoft using Segoe UI Light all over the place in its latest webpage designs. I recommend grabbing the updated versions of Segoe UI from Windows 8 for your Windows 7 or Windows Vista machines.

As others have complained, the lack of hinting in version 5.00 is particularly noticeable with lowercase bs, ds, ps and qs, the ‘round parts’ of which don’t line up well with other characters. The heights of numerals are also variable at some sizes.

Have a look at the following screenshots for a better idea of the differences (click the images to see the full sizes).

Version 5.00

Screenshot of Segoe UI Light 5.00

Version 5.15

Screenshot of Segoe UI Light 5.15

Difference

Screenshot of the difference between Segoe UI Light 5.15 and Segoe UI Light 5.00

When should a program’s UI animations be disabled?

Modern frameworks like the Windows Presentation Foundation, its relative Silverlight and the upcoming Windows Runtime make it easy to add animations to a program’s graphical user interface. When implemented well, animations subtly improve the user experience and can demonstrate a high level of polish in your application. The Zune client software and Windows Live Messenger both feature beautiful animations – coincidentally, both were written with internal Microsoft frameworks (Iris and ‘DirectUI’, respectively; the second is apparently unrelated to anything in WinRT). The Twitter client MetroTwit shows what can be done in WPF (its interface was inspired by the Zune software and the Metro design language).

There are times, however, when animations may become detrimental to the user experience. Animations may appear choppy on lower-end or older systems (especially with heavy frameworks like WPF), and in general they should be disabled entirely for Remote Desktop Connection sessions (only very fast networks with low latency may be able to handle them). Jossef Goldberg from the Visual Studio team has written about the efforts made to bring the performance of Visual Studio 2010 over remote connections up to par, and while his advice is mainly about WPF, the same principles apply to other frameworks, also.

So, how can we decide whether animations should be disabled or not? The answer will likely vary from project to project, but there are a few things that we can do:

1. Check if the program is running in a remote session

In Win32, use the GetSystemMetrics function to get the SM_REMOTESESSION metric (a non-zero result means it is a remote session). In WPF, use the SystemParameters.IsRemoteSession property in the System.Windows namespace. In Windows Forms, use the SystemInformation.TerminalServerSession property in the System.Windows.Forms namespace.

2. Check if animations are enabled in Windows

Windows Vista introduced many new animations to common controls like buttons (notice the smooth glow effect and compare it to the binary states found in Windows XP). Regrettably this change made most owner-drawn implementations look shoddy since they mostly lack animation (e.g. buttons in Firefox), but that’s a topic for another post.

Anyway, these animations can be switched off in the following dialog (aside: the list box was mercifully increased in size in Windows 7, though the window still isn’t resizable):Performance Options Screenshot

If the user has disabled animations here, it’s probably a good idea to respect that choice in any program you write. We can use the SystemParametersInfo function with the SPI_GETCLIENTAREAANIMATION parameter to check the system setting (or use the SystemParameters.ClientAreaAnimation property in the System.Windows namespace, but note that this always returns true in Windows XP). This only applies to Windows Vista and later.

3. WPF-only: Check the graphics rendering tier

The RenderCapability.Tier property in the System.Windows.Media namespace gives an indication of the graphical capabilities of the system. There are currently 3 tiers, and while the exact meaning may change between .NET releases (as it did in .NET 4.0), this property can be used to help determine what animations, if any, should be enabled.

4. Ask the user!

It can’t hurt to give the user a choice about animations. The remote session checks described above will work for RDP, but there are other technologies available, and we don’t want to punish VNC users by invalidating the entire window 60 times per second for some fancy animation, even if we can’t tell that they’re connecting remotely. If exposing such an option in the UI doesn’t make sense, at least offer it as a command line switch.

Addendum (2011-11-20)

Snooping around PresentationFramework.Aero.dll in .NET Reflector, I happened to come across the ‘Animates’ property in the ButtonChrome class (Microsoft.Windows.Themes namespace):

Similar properties can be found in the other *Chrome classes. Checking the computer’s power status isn’t something covered in this article, but it’s certainly a good idea.

Theming & Visual Styles in Windows 8

The following is based on the Windows Developer Preview and might not accurately represent the final version of Windows 8.

A significant change in Windows 8 is the removal of support for Windows classic theming. In the Windows Developer Preview, there is no Windows Classic theme, and all themes (including Windows Basic and the four high contrast themes) use the Desktop Window Manager (DWM) for desktop composition (in Windows Vista and Windows 7, it was only enabled for Aero themes).

While some users may miss the Windows Classic theme (it might return in later builds, of course), this is definitely a positive development. All themes will receive the benefits of hardware acceleration, and there will no longer be the need to maintain a separate code path for when the DWM is disabled (as long as the program targets only Windows 8 or later).

In order to maintain compatibility with earlier versions of Windows, when a high contrast theme is selected, Windows 8 will simulate the Windows classic theming model unless an application specifies Windows 8 as a supported OS in its application manifest. The sample program I made for the previous post did not include such a manifest, so it doesn’t work correctly in the Windows Developer Preview with high contrast themes:WPF sample without manifest

Compare this to a task dialog:

Task Dialog (High Contrast #1)

(The button in the WPF window is also drawn incorrectly, but presumably that will be fixed in .NET 4.5.)

Adding the appropriate manifest to the application causes it to work as it should:

WPF sample with manifest

I’ve updated the sample code in the previous post to include the manifest file.