Click here to Skip to main content
Click here to Skip to main content

Pocket PC Screen Rotation

, 12 Apr 2007
Rate this:
Please Sign up or sign in to vote.
A basic sample on how to rotate the screen of a pocket PC.

Introduction

This week I need to implement a feature to rotate screen of the pocket PC where my Application runs depending on the content of the selected screen. I started some research, but couldn't find anything about it. Actually I couldn't find even an idea where I should start.

I had a thought that such a feature could be implemented by using SystemParametersInfo API, so I went to MSDN and take a deeper look at its parameters. Nothing seemed to safisfy my needs.

So, started browsing the whole Windows CE 3.0 SDK. Once again, I couldn't find anything.

I decided to take a look at ChangeDisplaySettingsEx API, which I had already used several times before but for Win32 APPs, not for pocket PC applications. By looking at DEVMODE structure I saw the member dmDisplayOrientation, and noticed I was close to figuring out how to implement such a feature.

In fact, ChangeDisplaySettingsEx is present in both SDK's (Pocket PC and Win32).

Once I found that structure member there was no tricky to find out how to put it in action.

Using the code

The use of this API in order to flip/rotate the screen of a pocket PC is preety easy, but is very important to mention that it is not present in Windows CE 3.0 or earlier and the capabilty to flip the screen also depends on whether the display device supports it or not.

Before trying to flip the screen, it would be nice to check the device for such a support and, depending on the result warn the user about the lack of support of the device for Screen rotation.

Before going to the code itself, i'd like to list the angle constants below:

DMDO_0

Indicates that the display is on portrait mode.

DMDO_90

Indicates that the display is on landscape mode for people who uses right hand.

DMDO_180

Indicates that the display is upside-down portrait mode.

DMDO_270

Indicates that the display is on landscape mode for people who uses left hand.

Those constants is what we will use whenever we want to put the display at a given position, and they can also be used to determine what positions the device support.

Below I ilustrate how to check the device for what positions it supports:

//
// Check the device for capabilty to rotate the display
// 

DEVMODE DeviceMode;

memset(&DeviceMode, NULL, sizeof(DEVMODE));

DeviceMode.dmSize = sizeof(DeviceMode);
DeviceMode.dmFields = DM_DISPLAYQUERYORIENTATION;

ChangeDisplaySettingsEx(NULL, &DeviceMode, NULL, CDS_TEST, NULL);

Now you can perform a bit-wise operation towards the stuct member dmDisplayOrientation in order to find out what of those constants are supported. Of course if none of those constants are present in dmDisplayOrientation it means that the device does not support screen rotation.

Once you know the device supports screen rotation, you can query the current position of the screen, and it is done this way:

//
// Determine the current position of the screen
// 

DEVMODE DeviceMode;
    
memset(&DeviceMode, NULL, sizeof(DeviceMode));
DeviceMode.dmSize=sizeof(DeviceMode);
DeviceMode.dmFields = DM_DISPLAYORIENTATION;

if ( 
   DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettingsEx(
                            NULL, 
                            &DeviceMode, 
                            NULL, 
                            CDS_TEST, 
                            NULL
                            )
  )
//ChangeDisplaySettingsEx executed successfully
{
    switch (DeviceMode.dmDisplayOrientation)
    {
    case DMDO_0:
    //The display is currently in portrait mode

    case DMDO_90:
    //The display is currently in landscape mode 
    //for people who uses right hand

    case DMDO_180:
    //The display is currently in upside-down portrait mode

    case DMDO_270:
    //The display is currently in landscape mode 
    //for people who uses left hand

    }

}
        return DeviceMode.dmDisplayOrientation;
else
//Error executing ChangeDisplaySettingsEx

Finally, how to set the desired position:

//
// Change the position of the screen
//

DEVMODE DeviceMode;
    
memset(&DeviceMode, NULL, sizeof(DeviceMode));
DeviceMode.dmSize=sizeof(DeviceMode);
DeviceMode.dmFields = DM_DISPLAYORIENTATION;
DeviceMode.dmDisplayOrientation = DMDO_90; //Put your desired 
                       //position right here.

if (DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettingsEx(
                            NULL,
                            &DeviceMode,
                            NULL,
                            CDS_RESET,
                            NULL
                             )
   )
   //Screen was rotated successfully
else
   //Screen could not be rotated

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

hateeee

Norway Norway
No Biography provided

Comments and Discussions

 
GeneralSuper! It works! PinmemberAlexander Gorshkov26-Feb-09 4:38 
GeneralAnother one PinmemberFansHill25-Feb-09 1:58 
QuestionHow to use DEVMODE Pinmemberdontpanic158-May-07 18:44 
AnswerRe: How to use DEVMODE Pinmemberhateeee9-May-07 6:24 
GeneralRe: How to use DEVMODE Pinmemberdontpanic159-May-07 14:34 
GeneralRe: How to use DEVMODE Pinmemberhateeee11-May-07 2:49 
GeneralRe: How to use DEVMODE Pinmemberdontpanic1511-May-07 3:59 
GeneralJust a minor remark PinmemberVrda19-Apr-07 2:55 
Generale800 tools PinmemberETA12-Apr-07 22:46 
GeneralRe: e800 tools Pinmemberhateeee13-Apr-07 8:06 
GeneralRe: e800 tools PinmemberETA13-Apr-07 9:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 12 Apr 2007
Article Copyright 2007 by hateeee
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid