Rotating the Content of the Screen
Windows CE allows you to rotate the content displayed on a screen in increments of 90 degrees. Screen rotation requires support from the display driver, which maintains information regarding rotation. Screen rotation is currently supported only on devices that use a single screen and is not supported on multiple screen devices.
An application calls the ChangeDisplaySettingsEx function to determine the screen orientation modes that the system supports, to set the angle by which the screen is rotated, and to query the current angle of rotation.
To determine whether the driver supports screen rotation
Set the dmFields member of a DEVMODE structure to DM_DISPLAYQUERYORIENTATION.
Call ChangeDisplaySettingsEx with the lpMode parameter set to the DEVMODE structure and the dwFlags parameter set to CDS_TEST. The following code example shows how to call ChangeDisplaySettingsEx.
bCanRotate = ChangeDisplaySettingsEx(NULL, &devMode, NULL, CDS_TEST, NULL);
Examine the return value from ChangeDisplaySettingsEx. If the return value is DISP_CHANGE_SUCCESSFUL, the driver supports screen rotation. If the return value is DISP_CHANGE_BADMODE, the driver does not support screen rotation.
To obtain the current angle of rotation
Set the dmFields member of a DEVMODE structure to DM_DISPLAYORIENTATION.
Call ChangeDisplaySettingsEx with the lpMode parameter set to the DEVMODE structure and the dwFlags parameter set to CDS_TEST. The following code example shows how to call ChangeDisplaySettingsEx.
ChangeDisplaySettingsEx(NULL, &devMode, NULL, CDS_TEST, NULL);
Examine the dmDisplayOrientation member of the DEVMODE structure to determine the current angle of rotation. The following table shows the possible values of this member.
Value Description DMDO_0 The screen is not rotated. DMDO_90 The screen is rotated by 90 degrees counterclockwise. DMDO_180 The screen is rotated by 180 degrees counterclockwise. DMDO_270 The screen is rotated by 270 degrees counterclockwise.
To set the angle of screen rotation
- Set the dmFields member of a DEVMODE structure to DM_DISPLAYORIENTATION.
- Set the dmDisplayOrienation member of the DEVMODE structure to the value for the angle of rotation you want. The following table shows the possible values.
Value Description DMDO_90 Rotate the screen by 90 degrees counterclockwise. DMDO_180 Rotate the screen by 180 degrees counterclockwise. DMDO_270 Rotate the screen by 270 degrees counterclockwise. - Call ChangeDisplaySettingsEx with the lpMode parameter set to the DEVMODE structure and the dwFlags parameter set to CDS_RESET.
The following code example shows how to set the angle of screen rotation to 180 degrees, which displays the content of the screen upside-down.
devMode.dmFields = DM_DISPLAYORIENTATION;
devMode.dmDisplayOrientation = DMDO_180;
ChangeDisplaySettingsEx(NULL,&devMode,NULL,CDS_RESET,NULL);
When the screen is rotated, the OS notifies the following parts of the system about the new screen resolution:
Touch driver
The touch driver maintains information about the rotation angle of the screen. If the screen is rotated, GWES performs the necessary transformation of the coordinates for the new orientation.
Cursor and mouse
Window manager
The window manager sends a WM_SETTINGCHANGE message to the taskbar, which causes the taskbar to change its size to match the new screen resolution and updates all structures related to the screen resolution. The window manager also invalidates and forces the redrawing of all regions when the screen resolution changes because the screen was rotated.
The OS notifies an application about changes in screen rotation by sending a WM_SETTINGSCHANGE message to the applications. The application is responsible for responding to the new screen resolution and repainting any windows that the application created. If the application does not respond to the orientation change, the windows created by the application could become positioned outside of the current screen coordinates. An application should respond to this message by changing the size and position of its windows to match the new screen resolution.
See Also
How to Implement Screen Rotation
Last updated on Wednesday, April 13, 2005
© 2005 Microsoft Corporation. All rights reserved.