Handling Windows* 8 Auto-rotate feature in your application

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 ){       



For more complete information about compiler optimizations, see our Optimization Notice.



Yep you can definitely call the API natively in C#, thanks for adding that to this article.

migarc1's picture

If you are developing in C# you don't need to write C++. You can use the following link: http://forum.unity3d.com/threads/how-to-disable-rotate-screen-utility-by-code.264408/

ghhofeme's picture

Nice blog, Jeff! I have tweeted it for you. (@gh_intelblogs)

Add a Comment

Have a technical question? Visit our forums. Have site or software product issues? Contact support.