Smartphone Controls
The limited display and lack of touch screen or mouse on the Smartphone have driven Microsoft to modify the behavior of some of the standard controls. The goal is to make controls that are navigable from simple cursor commands as well as use very little space.The standard Windows CE controls still exist on the Smartphone. It's possible to create a standard list box in a Smartphone window, but once you navigate into a list box using the cursor keys, the control won't relinquish focus to other controls in the window because it uses the Up and Down cursor keys for internal navigation between the items in the list box. Standard multiline edit controls have the same problem. Other controls such as combo boxes don't make much sense in the limited screen space of a Smartphone. Because of this, Smartphone windows or dialog boxes use a limited and somewhat different set of controls. One of these enhanced controls is the oft-overlooked edit control.
Text Controls
Inputting text is a bit of a challenge on a Smartphone. The keyboard is limited to a number pad and a handful of cursor keys and is not conducive to text input. The Smartphone relies on the developer providing a context for the contents of the edit field, such as whether the control will contain numbers, words, or names. Depending on the context, the edit box can interpret taps on the numeric keypad in different ways.Most OEMs support two different text input modes on their Smartphones. The first is referred to as multitap and is familiar to anyone who has entered text on a cellular phone during the last 10 years. In multitap mode, multiple presses of each number key result in the system scrolling through the letters assigned to that number. The letters assigned are derived from the standard letter assignment that was set by American Telephone and Telegraph eons ago. Because that original assignment didn't include the letters Q and Z (a great trivia question, by the way), the layout has been slightly modified and is now an international standard. The layout is shown in Figure 19-6.

Figure 19-6: The standard letter assignments on a telephone keypad
When the user wants to enter a letter, the number assigned to the letter is tapped multiple times until that letter appears. For example to enter a K, the user would tap the 5 key twice. Each number scrolls through its assigned letters followed by its number. So tapping the 8 key multiple times would scroll through the characters T, U, V, and 8. Pausing between taps for a short time locks in the selection and moves the cursor to the right. The 1 key is used to enter standard punctuation characters such as . , ? ! - ' @ : 1. Tapping the * key makes the next letter upper case. The # key inserts spaces, and the 0 key enters 0.
There are special cases for some keys. Pressing and holding the # key displays a screen of symbols. The user can then use the cursor keys to select the symbol needed. Pressing and holding the # key switches between multitap mode, T9 mode, and numeric mode.T9 mode is a text-entry scheme that makes amazingly accurate guesses at what the user is trying to enter. The user taps the number key assigned to each letter and then types in the number for the next letter of the word, and so on. The T9 system makes a guess at the word from the possible combination of the letters possible from the first number and the letters from the second number. As more numbers are entered, the system predicts the word being entered with an almost uncanny accuracy. T9 works great with standard words but does have trouble with names.A third entry mode is numeric. As you might guess, this mode simply takes the assigned number for each key entered and places it in the edit box.Edit controls on the Smartphone have an enhanced interface over the standard run-of-the-mill Windows edit control. The first enhancement is the ability for the edit control to be switched between the various text input modes.The EM_SETINPUTMODE message sets the input mode of the control. The wParam value isn't used, but lParam can contain one of the following values: EIM_SPELL for multitap mode, EIM_AMBIG for ambiguous or T9 mode, EIM_NUMBERS for numeric mode, and EIM_TEXT for the default entry mode set by the user.In addition to the text mode, modifier flags can also be passed to set the shift state or the caps lock state. To change the shift state, the IMMF_SHIFT flag is combined with the text mode. To set the shift state, combine IMMF_SHIFT with IMMF_SETCLR_SHIFT. To clear the shift state, use IMMF_SHIFT alone. The caps lock state can be set in a similar manner. Passing the IMMF_CAPSLOCK flag indicates that the caps lock state is being modified. Combining IMMF_CAPSLOCK with IMMF_SETCLR_CAPSLOCK sets the caps lock state, whereas passing IMMF_CAPSLOCK alone clears the caps lock state.The current mode can be queried with the EM_GETINPUTMODE message. To query the default input mode of the control, pass FALSE in lParam. Passing TRUE in lParam returns the default input mode for the control if it does not have focus or the actual input mode if it does have focus. The actual and default can be different because the user can change the input mode by pressing and holding the # key.The EM_SETSYMBOLS message sets the symbols that are displayed when the user presses the 1 key. For this message, lParam points to a string that contains the symbols to be made available to the user.
The EM_SETEXTENDEDSTYLE message sets the extended edit style bits for the control. The wParam parameter contains a mask defining which of the extended style bits are to be changed. The state of each flag is set in lParam. So, to clear a particular extended style flag, the flag would be passed in wParam, but the corresponding bit in lParam would be 0 to indicate that the new state of the flag is to be 0.The only extended style bit currently defined is ES_EX_CLEARONBACKPRESSHOLD. This flag causes the control to interpret a press and hold of the Back key as a command to clear the contents of the edit control. To prevent this action, this style bit can be cleared by the application. This flag is set by default on single-line edit controls and cleared by default on multiline edit controls.
Expandable Edit Controls
Edit controls on the Smartphone can be made expandable with an up-down buddy control. In a dialog resource, the combination might look like the following:
EDITTEXT IDD_TEXT, 5, 60, 75, 12, WS_TABSTOP | ES_MULTILINE
CONTROL ", IDD_UDEDIT, UPDOWN_CLASS, UDS_AUTOBUDDY |
UDS_ALIGNRIGHT | UDS_EXPANDABLE | UDS_NOSCROLL,
0, 0, 0, 0
The first line defines the edit control, the up-down control is declared immediately afterward. The CONTROL resource tag is used for this control because the resource compiler doesn't use a specific keyword such as EDIT to declare an up-down control. The up-down control is assigned an ID value to identify the source of WM_NOTIFY messages it sends to its parent. The control doesn't need a position because its position will be defined by the location of the edit control. The up-down control's style flags configure it for this specific use. The UDS_AUTOBUDDY flag tells the control to associate itself with the closest control in the z-order. Because the edit box was declared immediately before the up-down control, the edit box will be closest in the z-order. The UDS_ALIGNRIGHT flag tells the control to attach to the right side of the edit control.UDS_NOSCROLL tells the up-down control not to display Up and Down arrows like a scroll bar. The Up and Down arrows can be used for incrementing and decrementing numbers in an associated edit control. Here, we simply want the Right arrow to indicate to the user that the edit control is expandable.
Finally, the UDS_EXPANDABLE flag indicates that the edit control is expandable. When the edit control has the focus and the user hits the action key, the edit control will be expanded to fill the entire screen, showing as much of the contents of the edit control as possible. The expanded mode is much like a multiline edit control in that the action key moves the cursor to a new line. A MenuBar is automatically created with OK and Cancel buttons to accept or discard any changes made in expanded mode. Figure 19-7 shows an expandable edit control in both normal and expanded modes.

Figure 19-7: An expandable edit control in normal and expanded modes
An expandable edit control can be created manually as well as through dialog resource definitions. The following code creates an expandable edit control manually.
hwndEdit = CreateWindow (TEXT("edit"), NULL, WS_VISIBLE |
WS_TABSTOP | ES_AUTOHSCROLL | ES_AUTOVSCROLL |
ES_MULTILINE, 9, 15, 100, 75, hWnd,
(HMENU)IDD_TEXT, hInst, 0L);
hwndUpDown = CreateWindow (UPDOWN_CLASS, NULL, WS_VISIBLE | UDS_AUTOBUDDY |
UDS_ALIGNRIGHT | UDS_EXPANDABLE | UDS_NOSCROLL,
0, 0, 0, 0, hWnd, (HMENU)IDD_UDTEXT, hInst, 0L);
SendMessage(hwndUpDown, UDM_SETBUDDY, (WPARAM)hwndEdit, 0);
The only difference between this code and the dialog resource is the sending of a UDM_SETBUDDY message to the up-down control to associate it with the edit control.
Spinner Controls
The spinner is a modified list box control buddied with an up-down control. The result is a single line control that can be spun to display each item in the list box. Unlike the standard list box, the spinner control uses the Left and Right cursor keys to spin between items in the box. As with other Smartphone controls, the Up and Down cursor keys transfer focus to the next control in the tab order.
Creating a spinner consists of creating both the list box and up-down controls. In a dialog resource, the combination would look like the following:
LISTBOX IDD_LISTCITIES, 5, 60, 75, 12, WS_TABSTOP
CONTROL ", IDD_CITIESUD, UPDOWN_CLASS,
UDS_AUTOBUDDY | UDS_HORZ | UDS_ALIGNRIGHT | UDS_ARROWKEYS |
UDS_SETBUDDYINT | UDS_WRAP | UDS_EXPANDABLE, 0, 0, 0, 0
The first line defines the list box. The only unusual thing about the declaration is that the list box is only 12 dialog units high, just tall enough for one item. The up-down control is declared immediately after the list box. The CONTROL resource tag is used for this control because the resource compiler doesn't use a specific keyword such as LISTBOX to declare an up-down control. The large number of style flags configures the control for this specific use. Many of the same style flags are used when creating expandable edit controls, so I'll only cover the new ones. The UDS_HORZ and flag tells the control to create Left and Right arrows instead of Up and Down arrows attached to the list box.The UDS_SETBUDDYINT flag tells the up-down control to manipulate the text of its buddy, in this case the list box, and have it scroll among the different items in the list. The UDS_WRAP flag tells the control to wrap the list so that if the list box is at the last item in the list and the user presses the right button, the list box will show the first item in the list.The up-down control can have the additional style flag of UDS_NOSCROLL. This flag prevents the user from spinning the data with the Left and Right cursor keys. This style isn't much use unless it's combined with the UDS_EXPANDABLE flag so that the control can be expanded, allowing the user to change the selection. When the user expands the spinner, it sends a WM_NOTIFY message to the parent window with the UDN_EXPANDING command. Figure 19-8 shows a spinner control in both normal and expanded modes.

Figure 19-8: A spinner control in normal and expanded modes
A spinner can also be created manually with two calls to CreateWindow, as shown here:
HWND hwndList = CreateWindow (TEXT("listbox"), NULL, WS_VISIBLE |
WS_BORDER | WS_TABSTOP, 5, 5, 75, 20, hWnd,
(HMENU)IDD_LISTCITIES, hInst, 0L);
HWND hwndUpDown = CreateWindow (UPDOWN_CLASS, NULL, WS_VISIBLE | UDS_HORZ |
UDS_ALIGNRIGHT | UDS_ARROWKEYS |
UDS_SETBUDDYINT | UDS_WRAP | UDS_EXPANDABLE,
0, 0, 0, 0, hWnd, 0, hInst, 0L);
SendMessage (hwndUpDown, UDM_SETBUDDY, (WPARAM)hwndList, 0);
Here, like in the expandable edit control, the only difference between the two methods is the extra message sent to the up-down control to tell it the ID of its buddy list box and a few manually added style flags needed when creating the list box.