Export (0) Print
Expand All

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

1/6/2010

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.

  1. Make sure your OS Design Project is selected in the Solution Explorer. From the Project menu, choose Add New Subproject.

  2. In the Windows Embedded CE Subproject Wizard dialog box, choose WCE Application.

  3. In the Subproject 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>.

  4. In the Windows Embedded CE Subproject Wizard, perform the following steps:

    1. Choose An empty project, and then choose Next.
    2. From the Release Type list, choose LOCAL, and then choose Finish.
  5. When project creation is complete, the project ScreenRotationProj is displayed in the Subprojects folder on the Solution Explorer.

  6. To add the sample application code to the project you just created, right click on the Source files node and select Add New Item.

  7. In the Add New Item dialog box, select the code branch. From the list of Templates, choose C++ File. Name the file rotation.cpp.

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

    Ee502830.note(en-US,WinEmbedded.60).gifNote:
    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.

Community Additions

ADD
Show:
© 2014 Microsoft