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:
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:
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
)
)
{
switch (DeviceMode.dmDisplayOrientation)
{
case DMDO_0:
case DMDO_90:
case DMDO_180:
case DMDO_270:
}
}
return DeviceMode.dmDisplayOrientation;
else
Finally, how to set the desired position:
DEVMODE DeviceMode;
memset(&DeviceMode, NULL, sizeof(DeviceMode));
DeviceMode.dmSize=sizeof(DeviceMode);
DeviceMode.dmFields = DM_DISPLAYORIENTATION;
DeviceMode.dmDisplayOrientation = DMDO_90;
if (DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettingsEx(
NULL,
&DeviceMode,
NULL,
CDS_RESET,
NULL
)
)
else