Click here to Skip to main content
15,879,535 members
Articles / Mobile Apps

Pocket PC Screen Rotation

Rate me:
Please Sign up or sign in to vote.
3.71/5 (6 votes)
12 Apr 2007CPOL2 min read 51.7K   39   11
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:

C++
//
// 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:

C++
//
// 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:

C++
//
// 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)


Written By
Norway Norway
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralSuper! It works! Pin
Alexander Gorshkov26-Feb-09 4:38
Alexander Gorshkov26-Feb-09 4:38 
GeneralAnother one Pin
FansHill25-Feb-09 1:58
FansHill25-Feb-09 1:58 
QuestionHow to use DEVMODE Pin
dontpanic158-May-07 18:44
dontpanic158-May-07 18:44 
AnswerRe: How to use DEVMODE Pin
Diogo Ferreira Lopes9-May-07 6:24
Diogo Ferreira Lopes9-May-07 6:24 
GeneralRe: How to use DEVMODE Pin
dontpanic159-May-07 14:34
dontpanic159-May-07 14:34 
GeneralRe: How to use DEVMODE Pin
Diogo Ferreira Lopes11-May-07 2:49
Diogo Ferreira Lopes11-May-07 2:49 
GeneralRe: How to use DEVMODE Pin
dontpanic1511-May-07 3:59
dontpanic1511-May-07 3:59 
GeneralJust a minor remark Pin
Vrda19-Apr-07 2:55
Vrda19-Apr-07 2:55 
Generale800 tools Pin
ETA12-Apr-07 22:46
ETA12-Apr-07 22:46 
GeneralRe: e800 tools Pin
Diogo Ferreira Lopes13-Apr-07 8:06
Diogo Ferreira Lopes13-Apr-07 8:06 
GeneralRe: e800 tools Pin
ETA13-Apr-07 9:50
ETA13-Apr-07 9:50 

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

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