Screen rotation under WinCE

Source: Internet
Author: User

Reprinted please indicate the source

Author: Pony


Recently, a screen rotation test on WinCE was conducted. my implementation is an application based on WinCE. There is a button in the display area. Every time you press this button, the screen will rotate for 90 degrees. I have been calling this stuff for three days. I encountered many problems and finally succeeded. The most important thing is that I have a deeper understanding of the display driver of wince. share it with you.

 

To implement the above functions, there are two main operations: one is to make some modifications to the operating system itself to support screen rotation driver. second, the upper-layer applications have made some changes in the graphic mode and processed related messages.

 

Step 1

Let's see if the display driver supports screen rotation. How can we see if the display driver supports screen rotation? Indicates that the driver class must be inherited from the gperotate class. and implement some of these methods. I should go to my current System BSP to check the source program under the display driver. my board is the fs2410 of youlong, and the display driver is under the smdk2410bsp package. open the DRIVERS directory. find the display folder. Everything in this folder is related to the display driver. in. h file I found the following lines of code.

#ifdef ROTATEclass S3C2410DISP : public GPERotate#elseclass S3C2410DISP : public GPE#endif //ROTATION

 

Obviously, s3c2410disp is the main implementation class of the display driver mentioned above. The system determines which base class the class inherits based on whether rotate is defined. the above two base classes are in GEP. H (which can be found under public/common/oak/INC. in addition, you can find the following statement in this file:

Typedef GPE gperotate;

Oh, the two classes are actually the same. only when implementing the class method, whether or not to perform different processing according to the rotate macro definition. in fact, the display driver in wince is implemented based on The GPE class. GPE is short for graphics primitive engine and implements some basic drawing RR operations, but most of them are pure virtual functions (so this class is also pure virtual class, you must inherit it), the inheritance class needs to implement most of the operations. the GPE implementation code is not publicly available at Microsoft. from the analysis of the wince driver structure, GPE is equivalent to MDD, while s3c2410disp is PDD. For our developers, you only need to implement the PDD part based on a specific hardware platform.

 

I looked around at. h and. cpp and found that there was no rotate macro definition, so the system does not support screen rotation by default. So I added a macro definition to s3c2410disp. h.

#ifndef ROTATE#define  ROTATE#endif

 

The s3c2410disp. cpp file does not need to be modified, because after the macro definition is added, the corresponding processing will be automatically performed in the implementation method.

 

Step 2

Open the source file in the same level directory and find the following lines of code:

TARGETLIBS=                                             /    $(_COMMONSDKROOT)/lib/$(_CPUINDPATH)/coredll.lib    /!IFDEF ROTATE    $(_COMMONOAKROOT)/lib/$(_CPUINDPATH)/emulrotate.lib       /    $(_COMMONOAKROOT)/lib/$(_CPUINDPATH)/gperotate.lib        /!ELSE    $(_COMMONOAKROOT)/lib/$(_CPUINDPATH)/emul.lib       /    $(_COMMONOAKROOT)/lib/$(_CPUINDPATH)/gpe.lib        /!ENDIF SOURCELIBS= /!IF "$(CLEARTYPE)" == "1"!IFDEF ROTATE    $(_COMMONOAKROOT)/lib/$(_CPUINDPATH)/rctblt.lib /!ELSE    $(_COMMONOAKROOT)/lib/$(_CPUINDPATH)/ctblt.lib /!ENDIF!ENDIF

It is easy to see whether rotate is defined. The linked library files are different (The GPE source code Microsoft is not public, that is, it is hidden in these library files), so we need to change it here, macro definition in source is slightly different from that in C. You only need to add

Rotate = 1

By now, the display driver can support screen rotation.

 

Step 3

Now you can write the application to test the screen rotation. but with the spirit of "Academic Research", I still want to go. CPP analyzes how Samsung engineers rotate the screen (only a few important implementation methods)

The main functions related to screen rotation are as follows:

void   S3C2410DISP::CursorOn (void)void   S3C2410DISP::CursorOff (void)

 

The above two functions are obviously enabling and disabling the cursor. When the screen supports rotation, these two functions need to be specially processed because the mouse also needs to be rotated during screen rotation.

void S3C2410DISP::SetRotateParms()SCODE  S3C2410DISP::BltPrepare(GPEBltParms *blitParameters)

 

The information found is as follows:

Called before the blit operation is already med. it allows the driver to setup the blit hardware for executing the operation, if it is supported. it must return the actual function to be called to perform the b1_operation, which can be
Default bits function provided in The GPE class

This function mainly sets the width and height of the screen at different angles. It is easy to think that 0 and 180 degrees are the same, and 90 and 270 degrees are the same.

 

Let's talk about the concept of surface.

M_pprimarysurface = new gpesurfrotate (m_nscreenwidthsave, m_nscreenheightsave, (void *) (m_virtualframebuffer), m_cbscanlinelength, m_modeinfo.format );

This row is assigned a pointer to the gpesurf class. The gpesurf class can also be seen as an image storage and display class, which is mainly a storage and display management for two-dimensional images. GPE can be regarded as a display-driven management class, while gpesurf is a video memory. the most important member variable of the gpesuf class is address m_pw.addr. This variable is associated with the m_virtualframebuffer variable of the s3c2410disp class and points to the stored two-dimensional image. surface, which can be said to be another form of bitmap, which can be directly accessed in the wince Driver (Bitmap won't work ).

 

Step 4

The upper layer is applied.

Create an application based on WinCE application under EVC, based on a single document. what I want to achieve is that there is a button in the customer zone. Every time I press this button, the screen will rotate for 90 degrees.

1. The code for creating a button is as follows. Add the following statement to wm_create.

hwndRotateButton = CreateWindow(TEXT("button"), TEXT("Rotate me"),              WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,30,30,100,75,hWnd,           (HMENU)1, ((LPCREATESTRUCT)lParam)->hInstance,NULL);           break;

 

Note that this (hmenu) 1 is the button ID, which will be used for event judgment in wm_command.

 

2. Add the following code to the switch of wm_command:

 

Case 1: // button "rotate me" event memset (& devmode, 0x00, sizeof (devmode); devmode. dmsize = sizeof (devmode); // devmode. dmfields = dm_displayqueryorientation; devmode. dmfields = dm_displayorientation; If (disp_change_successful = changedisplaysettingsex (null, & devmode, null, cds_test, null) {// MessageBox (text ("Change display OK! "), Null, mb_ OK); Switch (devmode. dmdisplayorientation) {Case dmdo_0: newangle = dmdo_90; break; Case dmdo_90: newangle = break; case when: newangle = dmdo_270; break; Case dmdo_270: newangle = dmdo_0; break; default: newangle = dmdo_0; break;} memset (& devmode, 0, sizeof (devmode); devmode. dmsize = sizeof (devmode); devmode. dmfields = dm_displayorientation; devmode. dmdisplayorientati On = newangle; If (disp_change_successful! = Changedisplaysettingsex (null, & devmode, null, cds_reset, null) {MessageBox (hwnd, text ("change to new setting error"), null, mb_ OK); return 1 ;} break;} else // failed to change the image mode. {MessageBox (hwnd, text ("failed to change graphic settings! "), Null, mb_ OK); return 1;} break;

 

Note that case 1 is the ID of the button. here, the main work of screen rotation can be seen that the changedisplaysettingsex function plays the most important role. In fact, to change the screen direction of an application, you can only use this function. for details about its usage, go to msdn. I just want to make a few notes.

The onrotate event contains the following statement:

Devmode. dmfields = dm_displayorientation

When dmfields is assigned such a value, changedisplaysettingsex is called. If cds_test is passed, the current angle of the screen can be obtained.

We can also confirm whether the system supports screen rotation before obtaining the current screen. Use the following two statements:

Devmode. dmfields = dm_displayqueryorientation;

Changedisplaysettingsex (null, & devmode, null, cds_test, null );

With the above two statements, you can view the value of the devmode. dmdisplayorientation field to know the current

 

Whether screen rotation is supported by the current system. If the value of this field is 0, screen rotation is not supported. If the value is 7, the rotation of the 90,180,270 angle is supported because of the following definition:

#define DMDO_0      0#define DMDO_90     1#define DMDO_180    2#define DMDO_270    4

 

3. After a new angle is set, the system sends the wm_settingchange message to all applications. the new graphic mode information will be returned through devmode. Our application should intercept the message to make some form adjustments. in addition, changing the form size will certainly trigger the wm_size message, so we can add these two messages.

Case wm_size: // re-determine the layout of the sub-window (for example, the button, because the sub-window cannot receive the wm_size message) // adjust the display of the menu bar accordingly. break; Case wm_settingchange: // refresh the monitor. the main task is to adjust the full screen window. if (wparam = settingchange_reset) // The Screen direction changes. {int nscreenx, nscreeny; nscreenx = getsystemmetrics (sm_cxscreen); // obtain the dimensions in the X and Y directions. nscreeny = getsystemmetrics (sm_cyscreen); movewindow (hwnd, 0, 0, nscreenx, nscreeny, true); // adjust the full screen window, that is, a single file form created by the program by default .} break;

 

In the two messages, I didn't do much, but I used annotations to explain what to do, because I have already implemented screen rotation, these two messages are mainly used to adjust and beautify some forms and perform some user interface experience work. there is a lot of work to be done when we really build a product.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.