Freigeben über


Creating a Project for the Screen Rotation Application (Windows CE 5.0)

Send Feedback

In this procedure, you will create a project in your OS design and add sample application source code to the project. The source files must be added to the project after it is created. This enables you to compile, link, and include the application in your run-time image.

The sample application code in this section uses the ChangeDisplaySettingsEx function. The code also shows how to set the DEVMODE structure to query the driver on the rotation angles it supports, get the current rotation angle, and set a new rotation angle.

Each time you run this application on the CEPC, the screen will be rotated clockwise by 90 degrees.

To create a project for the sample application

  1. From the File menu, choose New Project or File, and then, on the Projects tab, choose WCE Application.

  2. In the Project name box, type a name for the project, ScreenRotationProj. By default, Platform Builder stores the project in a directory immediately subordinate to your OS design directory. For example, %_WINCEROOT%\Public\<OS design name>\<Project Name>.

  3. Choose the Workspace Project radio button, and then choose OK.

  4. In the New Project Wizard, perform the following steps:

    1. In step 1 of 3, you would typically enter the appropriate information. For this example, leave these fields blank and choose Next.
    2. In step 2 of 3, choose An empty project, and then choose Next.
    3. In step 3 of 3, from the Release Type list, choose LOCAL, and then choose Finish.
  5. When project creation is complete, the project ScreenRotationProj is displayed in the Projects folder on the FileView tab.

  6. To add the sample application code to the project you just created, from the File menu, choose New Project or File.

  7. In the New Project or File dialog box, select the Files tab. From the list of options, choose C++ Source File, and in the File name box, type rotation.cpp. Ensure that this file will be added to the ScreenRotationProj project by selecting the check box.

  8. A window in the IDE opens for rotation.cpp. Cut and paste the following code into the window.

    Note   To make the following code example easier to read, error checking is not included. This code example should not be used in a release configuration unless it has been modified to include secure error handling.

    /**********************************************************************
    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
    PARTICULAR PURPOSE.
    
    Copyright (c) 1999 Microsoft Corporation. All Rights Reserved.
    
    MODULE: 
      rotation.cpp
    
    ABSTRACT: 
      This application code demonstrates the how you can set up the DEVMODE structure and use the ChangeDisplaySettingsEx function to rotate the screen. 
      Each time you run the executable for this code, the screen will rotate clockwise by 90 degrees.
    
    **********************************************************************/
    
    #include <windows.h>
    
    int
    WINAPI
    WinMain(
       HINSTANCE,
       HINSTANCE,
    #ifdef UNDER_CE
       LPWSTR,
    #else
       LPSTR,
    #endif
       int
       )
    {
       DEVMODE DevMode;
    
       int RotationAngles;
       int CurrentAngle;
       int NewAngle;
    
       //
       // Check for rotation support by getting the rotation angles supported.
       //
    
       memset (&DevMode, 0, sizeof (DevMode));
       DevMode.dmSize   = sizeof (DevMode);
       DevMode.dmFields = DM_DISPLAYQUERYORIENTATION;
    
       if (DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettingsEx(NULL, &DevMode, NULL, CDS_TEST, NULL))
       {
          RotationAngles = DevMode.dmDisplayOrientation;
          RETAILMSG(1, (L"ChangeDisplaySettingsEx supports these rotation angles %d", RotationAngles));
       }
       else
       {
          RETAILMSG(1, (L"ChangeDisplaySettingsEx failed to get the supported rotation angles."));
          RotationAngles = -1;
       }
    
       //
       // Get the current rotation angle.
       //
    
       memset(&DevMode, 0, sizeof (DevMode));
       DevMode.dmSize   = sizeof (DevMode);
       DevMode.dmFields = DM_DISPLAYORIENTATION;
    
       if (DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettingsEx(NULL, &DevMode, NULL, CDS_TEST, NULL))
       {
          CurrentAngle = DevMode.dmDisplayOrientation;
          RETAILMSG(1, (L"ChangeDisplaySettingsEx reports the current rotation as %d", CurrentAngle));
       }
       else
       { 
          RETAILMSG(1, (L"ChangeDisplaySettingsEx failed to get the current rotation angle."));
          CurrentAngle = -1;
       }
    
       //
       // Rotate to the "next" angle.
       //
    
       if (CurrentAngle >= 0 && RotationAngles >= 0)
       {
          NewAngle = CurrentAngle;
    
          do
          {
             NewAngle <<= 1;
    
             if (NewAngle == DMDO_0)
             {
                NewAngle = DMDO_90;
             }
    
             if (NewAngle > DMDO_270)
             {
                NewAngle = DMDO_0;
             }
          } while (!(NewAngle & RotationAngles) && (NewAngle != DMDO_0));
    
          memset(&DevMode, 0, sizeof (DevMode));
          DevMode.dmSize               = sizeof (DevMode);
          DevMode.dmFields             = DM_DISPLAYORIENTATION;
          DevMode.dmDisplayOrientation = NewAngle;
    
          if (DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettingsEx(NULL, &DevMode, NULL, CDS_RESET, NULL))
          {
             RETAILMSG(1, (L"ChangeDisplaySettingsEx changed rotation angle to %d", NewAngle));
          }
          else
          {
             RETAILMSG(1, (L"ChangeDisplaySettingsEx failed to change the rotation angle to %d", NewAngle));
          }
       }
    
       return 0;
    }
    
  9. Save the file by choosing File - Save, and close the file by choosing File - Close.

You are now done with configuring the sample application for screen rotation.

See Also

How to Implement Screen Rotation | Rotating the Contents of the Screen

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.