How to change the Screen orientation on a Phone / Pocket PC?

If you have a Windows Mobile 5.0 device like the one I recently got and were wondering how do I change the screen orientation, well its fairly easy. It is cool that the screen orientation changes between landscape and portrait when I slide out the keyboard. But, on rare occasions I want to change the orientation without sliding out the keyboard and it is a pity that there is no hardware button to do this.

Programmatically this is a simple task. If you are using C++, all you need to do us use the ChangeDisplaySettingsEx class and change the DM_DISPLAYORIENTATION value for the lpDevMode member type. The supported screen settings are returned via lpDevMode.dmDisplayOrientation, with a DMO_0 meaning that screen rotation is not supported by the device. Also, when the display mode is changed a WM_SETTINGCHANGE message is send to all apps.

If you are more of a managed code kind of a person and rather use that, then it is even simpler. When you create a new Windows Mobile 5.0 Pocket PC device application project, your solution should automatically have a reference to the Microsoft.WindowsCE.Forms assembly. If for some reason you don’t have then then add the reference to this assembly. It usually resides in the same location where you installed the CF SDK (e.g. in my case this is C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\2.0\v2.0\WindowsCE\Microsoft.WindowsCE.Forms.dll).

In the SystemsSettings class, use the ScreenOrientation property to change the screen orientation (these are static). The possible values are 0, 90, 180, 270 (depicting angles), with the default being 0. To change the screen orientation between Landscape and Portrait you change the angle between 0 and 90 degrees as shown in the c# code snippet below.

Note, this only supported in .NET CF 2.0.

1 if (SystemSettings.ScreenOrientation == ScreenOrientation.Angle0) 2 //change to landscape 3 SystemSettings.ScreenOrientation = ScreenOrientation.Angle90; 4 else 5 //change to portrait 6 SystemSettings.ScreenOrientation = ScreenOrientation.Angle0;

 

[I’m rocking out to Veronicas – Everything I’m Not [Jason Nevins Remix]

Published by

Amit Bahree

This blog is my personal blog and while it does reflect my experiences in my professional life, this is just my thoughts. Most of the entries are technical though sometimes they can vary from the wacky to even political – however that is quite rare. Quite often, I have been asked what’s up with the “gibberish” and the funny title of the blog? Some people even going the extra step to say that, this is a virus that infected their system (ahem) well. [:D] It actually is quite simple, and if you have still not figured out then check out this link – whats in a name?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.