dcsimg
December 5, 2016
Hot Topics:

Porting Applications from the Pocket PC to Smartphone 2002

  • May 22, 2002
  • By Yaroslav Goncharov
  • Send Email »
  • More Articles »

Behavior

Often a user interface of applications relies on mouse (stylus) events. Smartphone 2002 does not have a chance to produce a click because it does not have a touch screen. In our case, we have a very simple application, but it cannot work without a touch screen! The problem is that list boxes use click events for navigation. We will replace those clicks with the special menu item in the menu bar.

Implementation

Expandable list and edit boxes

We need to reduce the height of the list boxes and add spin controls for items' selection and for expanding. The following resource code creates one list box with the desired functionality.

LISTBOX   IDL_LISTBOX,4,15,131,10,
          WS_TABSTOP | WS_VISIBLE | LBS_NOINTEGRALHEIGHT
CONTROL   "", IDC_UPDOWN, UPDOWN_CLASS, 
          WS_VISIBLE | UDS_AUTOBUDDY | UDS_HORZ | UDS_ALIGNRIGHT |
          UDS_ARROWKEYS | UDS_SETBUDDYINT | UDS_WRAP | UDS_EXPANDABLE,
          0,0,0,0

The following resource code creates an expandable edit box. Because it is a viewer application, the read-only flag is applied.

EDITTEXT   IDE_TEXTOUT,4,70,131,12,ES_MULTILINE | ES_AUTOVSCROLL |
           ES_AUTOHSCROLL | ES_READONLY | WS_TABSTOP
CONTROL    "", IDC_UPDOWN, UPDOWN_CLASS, UDS_AUTOBUDDY | 
           UDS_ALIGNRIGHT | UDS_EXPANDABLE | UDS_NOSCROLL,
           0, 0, 0, 0

Menu bar

The menu bar resource is a new resource and the resource editor does not handle it correctly. There are two known problems connected with menu bar resources: an undefined I_IMAGENONE keyword and converting a menu bar resource to binary format by the resource editor.

To solve those problems, I put the menu bar resource into the separate custom resource file. To do it, I created a separate text file and added the following menu bar code to it.

IDR_MENUBAR RCDATA
BEGIN
   IDR_MAINMENU, 
   2,            
   I_IMAGENONE, IDM_ENTER, TBSTATE_ENABLED,
   TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE, IDS_ENTER, 0, NOMENU,
   I_IMAGENONE, IDM_BACK, TBSTATE_ENABLED,
   TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE, IDS_BACK, 0, NOMENU,
END

Then I saved the file as PSPCMonkey.rc2 and added it to the project. The last step was to include this file IN the compile time resource includes, using the View->Resource Includes menu item.

This approach solves the problems with this custom resource. Now the menu bar resource cannot be edited in the resource editor; it should be edited as a text file.

Also, we need to add strings that are used in the menu bar to our string table, as shown below.

  STRINGTABLE DISCARDABLE 
  BEGIN
    IDS_BACK                "Back"
    IDS_ENTER               "Enter"
  END

Back key

The Back key should return the user to the previous screen. In edit controls, it also functions as a Backspace key. All edit boxes in our application are read-only; therefore, presssing the Back key in the main window should hide our application. It is recommended that you return the user to a "fresh" state each time an application is executed. The Back key then will close our dialog.

To implement this behavior, we should not override the Back key in our dialog. In this case, the Back key sends WM_COMMAND/IDANCEL to the dialog box. We need only to add the standard handle to the main switch of the DialogProc.

 ...
 case WM_COMMAND:
   switch (LOWORD(wParam))
   {
     // User chose to close the dialog
     case IDCANCEL:  //Handles the BACK KEY
       EndDialog(hDlg, TRUE);
       break;
     ...

Title bar

Due to the limited size of the task bar, an application title should be short and concise. Also, the title can be changed for the child windows. For example, a message box will show its title in the title bar. In our application, the title bar will show "Registry Editor" for the main window and "Error" for message boxes with error messages.

Labels

The standard Smartphone 2002 applications (for example, Inbox) use 11-point bold Nina for the labels, and not the current dialog font. The following code creates this font.

HFONT CreateLabelFont()
{
  LOGFONT lf;
  memset(<, 0, sizeof(LOGFONT));
  HDC hdc = ::GetDC(NULL);
  lf.lfHeight = -11 * GetDeviceCaps(hdc, LOGPIXELSY) / 72;
  ::ReleaseDC(NULL, hdc);
  lf.lfWeight = FW_SEMIBOLD;
  return CreateFontIndirect(<);
}

Now we can assign the created font to the labels in WM_INITDIALOG handler.

g_hLabelFont = CreateLabelFont();
::SendDlgItemMessage(hDlg, IDC_STATIC1, WM_SETFONT, (int) g_hLabelFont, 0);
::SendDlgItemMessage(hDlg, IDC_STATIC2, WM_SETFONT, (int) g_hLabelFont, 0);
::SendDlgItemMessage(hDlg, IDC_STATIC3, WM_SETFONT, (int) g_hLabelFont, 0);
::SendDlgItemMessage(hDlg, IDC_STATIC4, WM_SETFONT, (int) g_hLabelFont, 0);

And destroy the font when it is no longer needed (in WM_DESTROY handler).

 case WM_DESTROY:
   DeleteObject(g_hLabelFont);
   break;

Conclusion

From the compiler point of view, it is easy to port a Windows CE application that does not use MFC to the Smartphone 2002 platform. However, porting will not be so easy. Your main efforts will be spent on the user interface design. You should design your windows for the small content area; consider new controls, new behavior that does not consume mouse clicks, the Back button, and a title bar.

It seems that most applications should save their usability. We have lost a touch screen, a lot of content area, and some controls, but we have gotten expandable list and edit boxes, spinners, scrollable dialogs, and a lot of hardware keys. I think that those new aspects should compensate the lost ones for applications that can be considered useful on the Smartphone 2002 platform.

Download

Download demo project -- (18 KB)

# # #





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel