A Windows Mobile program that uses local code to implement screen orientation adaptive

Source: Internet
Author: User

In the application development process of Windows Mobile platform, how to deal with the impact of screen direction changes on the program is an important issue. Allen Lee's article WM about (4): Processing screen rotation describes how to use the OrientationAware control in the Mobile Client Software Factory to handle screen direction changes, the advantage is that we don't need to add any code. In my previous articles "Docking and Anchoring Controls on Windows Mobile" and "Creating a Windows Mobile UI program with good compatibility, it is mentioned that the control's own Docking and Anchoring can be used to adapt to changes in the device's screen direction. Today, I saw an article in The msdn technical article "Developing Orientation-Aware and Resolution-Aware Windows Mobile-based Applications in Native Code". this article describes how to use native code to handle the impact of the changes in the portrait/landscape modes on the device UI, and I think it is necessary to share it with you.

This article uses Crossword as the background. Before the portrait/landscape mode of the device is not processed, the program runs in portrait mode. However, in landscape mode, some controls are out of the display range, and the background looks incorrect, as shown in 1:

Figure 1: unhandled Program Interface

The solution can be divided into several steps:

1. Prepare a 320*320 background image to replace the original 240*320 background image.

2. In OnPaint event processing, the code for modifying the background image is as follows:

BitBlt (hDC, 0, 0,320,320, hMemDC, 0, 0, SRCCOPY );

3. In WndProc WM_SIZE processing, modify the width of the text box. The Code is as follows:

Code
1 case WM_SIZE:
2
3 {
4
5 HWND hEditBox = GetDlgItem (hWnd, IDC_MAIN_EDIT_BOX );
6
7 HWND hEnterButton = GetDlgItem (hWnd, IDC_MAIN_ENTER_BUTTON );
8
9 INT nWidth = LOWORD (lParam );
10
11
12
13 MoveWindow (hEditBox, 8, 4, nWidth-70, 20, TRUE );
14
15 MoveWindow (hEnterButton, nWidth-57, 4, 50, 20, TRUE );
16
17}
18
19 break;

 

4. Write a function to determine whether the height of the current screen is smaller than 320. The Code is as follows:

Code
1 BOOL InWideMode ()
2
3 {
4
5 int height = GetSystemMetrics (SM_CYSCREEN );
6
7 return (height <320 )? TRUE: FALSE;
8
9}

 

5. In OnPaint event processing, add a prompt box for processing. The Code is as follows:

Code
1 RECT rTallMode = {25,200,230,245 };
2
3 RECT rWideMode = {240, 43,311,185 };
4
5 RECT & r = InWideMode ()? RWideMode: rTallMode;
6
7 HBITMAP hPattern = LoadBitmap (g_hInst, MAKEINTRESOURCE (IDB_PATTERN ));
8
9 HBRUSH hNewBrush = CreatePatternBrush (hPattern );
10
11 HBRUSH hOldBrush = (HBRUSH) SelectObject (hDC, hNewBrush );
12
13 Rectangle (hDC, r. left, r. top, r. right, r. bottom );
14
15 SelectObject (hDC, hOldBrush );
16
17 DeleteObject (hNewBrush );
18
19 DeleteObject (hPattern );

 

6. Add the corresponding information of each dialog box in landscape mode, that is, add the corresponding *** _ WIDE dialog box in the resource dialog box directory, and adjust its controls accordingly.

7. In the WM_SIZE processing of the respective dialog box, modify the code so that it can adapt to the screen mode. The Code is as follows:

Code
1 case WM_SIZE:
2
3 {
4
5 RelayoutDialog (g_hInst, hDlg, InWideMode ()?
6
7 MAKEINTRESOURCE (idd_tools_options_javaswide ):
8
9 MAKEINTRESOURCE (IDD_TOOLS_OPTIONS_1 ));
10
11}
12
13 return TRUE;
14
15
16
17 case WM_SIZE:
18
19 {
20
21 RelayoutDialog (g_hInst, hDlg, InWideMode ()?
22
23 MAKEINTRESOURCE (IDD_TOOLS_OPTIONS_2_WIDE ):
24
25 MAKEINTRESOURCE (IDD_TOOLS_OPTIONS_2 ));
26
27}
28
29 return TRUE;
30
31

 

Then, recompile the modified program and debug it in the simulator. The effect is shown in Figure 2:

Figure 2: Modified Program Interface

 

Reference link:

WM has about (4): Processing screen Rotation

Docking and Anchoring Controls on Windows Mobile

Create a compatible UI program on Windows Mobile

Developing Orientation-Aware and Resolution-Aware Windows Mobile-based Applications in Native Code

Related Article

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.