Share via


How Applications Detect and Respond to Screen Rotation

Send Feedback

Generally, the user initiates a screen rotation either by pressing the screen rotation program key or by choosing a new screen orientation from the General tab of the Screen application, accessible from the Settings control panel.

Note   The screen can also be rotated programmatically with the Windows CE ChangeDisplaySettingsEx function. For example, to programmatically rotate the screen into right-handed landscape mode, call ChangeDisplaySettingsEx with a DEVMODE::dmDisplayOrientation value of DMDO_270.

With each change in screen orientation, Windows CE performs the following actions automatically:

  • Resizes full-screen windows to the new orientation and sends each of them the WM_SIZE notification.

  • Sends top-level windows the Windows CE WM_SETTINGCHANGE message.

    Note   Windows CE does not send notifications to child windows, which are based on the WS_CHILD style, even if the child window is a full-screen window. When the parent window of a child window resizes, you must ensure that the child window displays properly.

The WM_SIZE notification contains an lParam parameter that indicates whether a screen rotation has occurred. Its low-order word specifies the new client area width, and its high-order word specifies the new client area height. To use the WM_SIZE notification to determine whether a screen rotation has occurred, your code should perform a check to determine whether the screen dimensions have been reversed. If so, you can go ahead and process a block of code that displays the alternate screen layout.

The lParam's low-order and high-order words do not swap perfectly. The height of a full-screen window in landscape mode is slightly less than the width of a full-screen window in portrait mode because the navigation and menu bars take up some of that screen height in landscape mode.

Windows CE does not automatically resize windows that are not full-screen. A window is considered full-screen if its top, left, and right coordinates are at or outside the client area boundaries. The client area is the entire screen area below the title bar. For application windows that are not full-screen, you can use the Windows CE WM_SETTINGCHANGE message to detect and respond to screen rotations.

The Windows CE WM_SETTINGCHANGE message contains a wParam parameter that contains the value SETTINGCHANGE_RESET when a screen rotation has occurred. To use the WM_SETTINGCHANGE message, your code should perform a check to determine whether the wParam parameter equals SETTINGCHANGE_RESET. If so, you can go ahead and process a block of code that displays the alternate screen layout.

To detect and respond appropriately to a screen rotation, your application window must process one or both of these notifications and then redisplay its contents with an alternate layout that fits the new client area dimensions. You give them this functionality by including case statements for one or both notifications in the switch selection statement in their WndProc functions, as shown in the following example.

switch (uMessage)
{
    case WM_SIZE:
        // Determine whether lParam's low-order
        // and high-order words have swapped.
        if (...)
        {
            // Redraw to fit the dimensions of the new client area.
            ...
        {
    break;

    case WM_SETTINGCHANGE:
        // Determine whether wParam's contains 
        // the value SETTINGCHANGE_RESET.
        if (wParam == SETTINGCHANGE_RESET)
        {
            // Redraw to fit the dimensions of the new client area.
            ...
        }
    break;
}

For more information on rotating the screen programmatically, see "Rotating the Content of the Screen" in the Windows CE documentation on MSDN.

See Also

Design Options for Screen Rotation | Screen Orientation Modes

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.