Handling Windows* 8 Auto-rotate feature in your application

By Jeff M Laflam, Published: 01/10/2013, Last Updated: 01/10/2013

There is an interesting new feature that has been introduced in Windows* 8. This new feature allows the desktop to rotate as you rotate your tablet and/or Ultrabook™ with sensors.  I recently ran into an interesting situation with a popular game that we were recently working on so I thought I would share our learnings here.

 The feature is called auto-rotate and it changes the screen orientation from landscape to portrait to the flipped versions of those two when you physically rotate your Ultrabook system.

 This feature can be set on/off by selecting the Allow the screen to auto-rotate check box on your screen resolution property page, as shown below.


Simple enough, right? I never thought twice about this until we worked with Firaxis* Games on a touch version of their popular game Civilization V: Gods & Kings™.  Shortly after the game had released it was tested on several of the latest Ultrabook ™ convertibles. When the systems were rotated we noticed some applications were crashing or not behaving properly. Major portions of the application window extended beyond the visible desktop when the system was rotated to anything but landscape.  Going into portrait mode meant the application would have to be in some very odd resolution like 900x1600.  The application or game has to be designed to handle these situations and since this is a new feature many applications are not supporting it properly yet.  Civilization V: Gods & Kings was different though; it behaved as expected and did not allow windows to go into portrait mode or crash instead.it  allowed landscape and landscape flipped modes and maintained the proper resolution.

I started to investigate what  had been done differently.  In looking at the code I saw the following API call (SetDisplayAutoRotationPreferences). Clearly, this API was the missing link.  The question was:  which header file is needed to access it? A Google search ended up blank.  I was expecting to find an MSDN article.    I ended up asking the engineer at Firaxis, Marc Meyer, who implemented touch on Civilization V: Gods & Kings how he found it.  It turns out that he found it in “winuser.h. Since other developers are also having troubles finding the SetDisplayAutoRotationPreferences API call I thought it would be a good idea to provide some help via this blog. Perhaps developers who read this will also pass the word along via their communication channels.

Below is a brief snippet of code that I put into a sample and tested.  I used GetProcAddress to use the function because I didn’t want to link to the Windows 8 SDK which can cause backwards compatibility issues.


ORIENTATION_PREFERENCE_NONE              = 0x0,   








pARP = (pSDARP) GetProcAddress( GetModuleHandle(TEXT("user32.dll")),  "SetDisplayAutoRotationPreferences"); 

if( pARP ){       



Product and Performance Information


Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804