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.

Windows Theme Fonts Redux & Sample Code

View source on GitHub.

In a post earlier this year, I investigated how to retrieve information about theme fonts in Windows. Briefly, the Visual Styles APIs can be used when visual styles are enabled, but values need to be hard-coded (to some extent) otherwise.

Andrew Powell commented on my previous post noting difficulties in implementing the GetThemeFont function in managed code. In this post, I’ll demonstrate how to implement the relevant functions in a simple WPF project. In particular, I’ll focus on displaying information about the ‘main instruction’ text style as seen in Task Dialogs.

Read on for details.

Continue reading “Windows Theme Fonts Redux & Sample Code”

Replacement Lisp Icon

GNU CLISP under Windows sets the default icon for Lisp files (.lisp, .lsp, .cl) to this:

Default Lisp Icon

I decided to make a new icon based on the style found in recent versions of Visual Studio:

C# Icon

This is what I came up with:

Lisp Icon

The .ico file includes 32-bit images at sizes 256x256px (PNG-compressed), 48x48px, 32x32px and 16x16px. The font used to draw the lambda is Cambria Math.

lisp.ico
32,630 bytes; SHA-1: 848C7B8A6A7CDE3115893CE63848CEF2F4A33762

Windows 8: Bypassing the Start screen

After using the Windows Developer Preview (that is, Windows 8 pre-beta) build for a little while, I’m not at all sold on the Start screen as a replacement for the Start menu for keyboard-and-mouse users. I’m not giving up all hope yet, though – I wasn’t overly fond of the Backstage view when I first tried early builds of Office 2010, which similarly replaced what was a simple menu in Office 2007 with a full screen experience, but I’ve since grown to like it. And, of course, development is far from over at this stage.

I’ll be very surprised if I end up using any ‘Metro style’ applications on my desktop or laptop PCs, however. I’m happy to revisit this statement after Windows 8 launches, but the experience does seem much more suited to tablet and phone form factors (and I’d take a traditional PC any day).

There doesn’t seem to be an official way to disable the Start screen, which is not surprising (it would be akin to disabling the ribbon in Office 2007/2010). What is surprising is that it’s actually quite easy to do: just rename shsxs.dll in %windir%System32 and restart (thanks givebackstartmenu): voilà! The highly usable Start menu of Windows 7 returns. It will be interesting to see whether this remains an ‘option’ in future builds. Note that this disables the modern Task Manager, and potentially breaks other functionality, too.

A less radical option is enabling the Group Policy setting ‘Do not show the Start Menu when the user logs in’ (User ConfigurationAdministrative TemplatesStart Menu and Taskbar). This will open the traditional desktop directly after logging in, skipping the Start screen (but leaving it enabled). My initial impression is that this should be the default for non-touch/stylus form factors, but I’ll keep an open mind about that. Unfortunately, this setting isn’t actually working for me (possible PEBKAC). It seems to be connected to a DWORD in the Registry called ‘DontShowStartMenuOnLogin’. Modifying this also has no effect in the Windows Developer Preview.

Installing an OEM Xbox 360 Wireless Controller Receiver

Not wanting to pay the full retail price for a Microsoft Xbox 360™ Wireless Gaming Receiver for Windows®, I bought a knock-off from eBay. It turns out that you do get what you pay for – the drivers that came on the 80mm Mini CD were very old and didn’t work with Windows 7.

For anyone in a similar situation, here’s what I did to get everything working as it should (thanks are owed to jamesw1 for finding this solution):

  1. Download and install the latest Xbox 360 Accessories Software (version 1.2 at the time of writing).
  2. Plug in the device and open Device Manager (searching in the Start Menu is probably the quickest way to get there). Find your device in the list (it might be listed as an Unknown Device, though mine was labelled correctly), right click it and select ‘Update Driver’. Select ‘Browse my computer for driver software’, then ‘Let me pick from a list of device drivers on my computer’. Pick ‘Microsoft Common Controller for Windows Class’, click ‘Next’, then select ‘Xbox 360 Wireless Receiver for Windows’ and click ‘Next’ again. You will be given an ‘Update Driver Warning’ – click ‘Yes’ (and don’t blame me if your computer and/or controller blow up). That’s all.

Finally, apparently these drivers are recommended for some applications: XInput Force Feedback Driver (XInput 用フォース フィードバック ドライバ). You should be able to navigate the Japanese on that page – the platforms and languages are spelled out quite clearly.

Screenshot of Device Manager

Installing CUSP (Eclipse Lisp Plugin)

Update (2011-09-28): My own instructions didn’t work when I tried to install Eclipse and CUSP on a new machine. After much trial and error, I finally got a working setup by downloading a newer version of CUSP from here (version 1.0.414). This seems to work with SBCL 1.0.51 and Eclipse 3.7 (I downloaded the Classic package, in case that is significant). There no longer seems to be any need to copy the SBCL files to the plugin sub-directory. The CUSP maintainer has forked CUSP into a new project called Lispdev, which might be worth checking out.

For anyone struggling to install CUSP (a Lisp plugin for Eclipse) in a Windows environment, I hope these steps will work for you:

  1. Install the Steel Bank Common Lisp compiler.
  2. Download/extract Eclipse.
  3. Download CUSP from Sergey Kolos’ Eclipse Update Site (latest files here) and put jasko.tim.lisp.libs_1.1.1 and jasko.tim.lisp_0.9.390 in Eclipse’s plugins directory.
  4. Make a directory called sbcl in jasko.tim.lisp_0.9.390 and copy everything from your Steel Bank Common Lisp installation directory there (sbcl.exe, sbcl.core and all the sub-directories).

Everything should now work correctly (open the Lisp perspective in Eclipse via Window → Open Perspective → Other → Lisp).

Screenshot of CUSP in Eclipse 3.7

Changing the Synaptics ‘ChiralScroll’ Cursor

The Synaptics Gesture Suite enables a variety of useful features for supported laptop touchpads. My favourite is ‘ChiralScroll’, which allows you to scroll by making a circular motion on the touchpad. Synaptics actually offers generic drivers on their website now, so you can download them directly without needing to go via the usual websites.

Unfortunately, the cursor used for ChiralScroll leaves a lot to be desired:

Default ChiralScroll Cursor

At the very minimum, it doesn’t mesh well with the cursors found in the Windows Aero theme. I decided this would be a better cursor:

New ChiralScroll Cursor

I’m misappropriating the ‘Move’ cursor here (a separate metaphor), but I think the image fits with scrolling to some extent. Let me know if you can come up with a better alternative.

Read on for instructions on replacing the cursor.

Continue reading “Changing the Synaptics ‘ChiralScroll’ Cursor”

Windows Theme Fonts

View source on GitHub.

Update: See this post for a sample implementation in WPF.

Screenshot of Task Dialog (Aero)

Have you ever wondered how to access the various font colours and styles found throughout Windows, such as that of the ‘Main Instruction’ text in the Task Dialog shown above?

If you are using WPF, the SystemFonts class might sound promising at first. However, this class only exposes the following: the icon font, caption font, small caption font, menu font, message font and status font. These aren’t very exciting – in fact, they are all simply 9pt Segoe UI in Windows Vista/7 Aero. (Aside: early Windows 8 builds use 11pt Segoe UI Semilight as the caption (and small caption) font.) For those using Win32 directly, the SystemFonts class wraps around the SystemParametersInfo function (specifically with the messages SPI_GETNONCLIENTMETRICS and SPI_GETICONTITLELOGFONT) the GetThemeSysFont function.

MSDN offers some guidance on default fonts and colours in Windows Vista/7: apparently ‘Main Instruction’ text is 12pt #003399 Segoe UI. This table, while helpful, is not comprehensive, and in general it’s not a good idea to hard-code this kind of thing, as themes/visual styles are liable to change.

The keys lie in the Visual Styles APIs, introduced in Windows XP. In particular, the GetThemeFont function and GetThemeColor function (with the TMT_TEXTCOLOR property identifier), both found in UxTheme.dll. We simply need to specify the ‘part and state’ of the control in question (these are defined in Vsstyle.h and Vssym32.h). ‘Main Instruction’ text, for example, is referenced by the TEXT_MAININSTRUCTION part in the TEXTSTYLE class.

Screenshot of Task Dialog (Classic)

Regrettably, visual styles APIs only work when visual styles are enabled (who’d have thought it?). That is to say, we can’t rely on them with classic themes (Windows Classic and the High Contrast themes).

I emailed the very knowledgeable Larry Osterman about this, and he was kind enough to respond:

AeroStyle.xml tells which metrics to ask for which theme parts (for the OS that matches the version of the SDK it’s in), but there’s no theme API support for classic modes.

Basically they get the metric they’re looking for from the AeroStyle.xml file.

AeroStyle.xml is included in the latest versions of the Windows SDK. It contains the same classes and parts and states mentioned earlier in an XML format. The ‘MainInstruction’ part in the ‘TextStyle’ class looks like this, for instance:

Of interest are the ‘ClassicValue’ elements. When visual styles are disabled, it seems that ‘Main Instruction’ text uses the caption font (8pt bold Microsoft Sans Serif, as it happens).

In closing: you can use GetThemeFont and GetThemeColor if visual styles are enabled, but you will need look at AeroStyle.xml and hard-code the classic theme fall-back values.