Dialog Boxes
Message boxes will only get you so far on a Smartphone. Dialog boxes, or dialogs, can be created on the Smartphone as long as a few rules are observed. As on the Pocket PC, dialog boxes on the Smartphone must be sized to fit the full screen. This is accomplished with a call to SHInitDialog during the handling of the WM_INITDIALOG message. Smartphone dialogs must also create a SoftKeyBar control to provide a place for key input and to handle the Back button if the dialog contains one or more edit boxes.The following code shows the handling of a WM_INITDIALOG message for a typical Smartphone dialog box that contains at least one edit control.
// Specify that the dialog box should stretch full screen
SHINITDLGINFO shidi;
memset (&shidi, 0, sizeof(shidi));
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN/*SHIDIF_FULLSCREENNOMENUBAR*/;
shidi.hDlg = hWnd;
if(!SHInitDialog(&shidi))
return FALSE;
// set up MenuBar menu
SHMENUBARINFO mbi;
memset (&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hWnd;
mbi.nToolBarId = ID_MENUDLG;
mbi.hInstRes = hInst;
// If we could not initialize the dialog box, return an error
if (!SHCreateMenuBar(&mbi)) {
DestroyWindow (hWnd);
return FALSE;
}
// Override back key since we have an edit control
SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK,
MAKELPARAM (SHMBOF_NODEFAULT | SHMBOF_NOTIFY,
SHMBOF_NODEFAULT | SHMBOF_NOTIFY));
// set the title bar
SHSetNavBarText (hWnd, TEXT("Dialog Title Text"));
Navigating controls in a Smartphone dialog is different from a standard Windows CE system because the Smartphone doesn't have a Tab key to transfer focus between controls. Instead, controls within a Smartphone dialog box are organized vertically, and the Up and Down cursor keys are used to switch focus to the next control in the tab order. (The control order is still referred to as tab order even though the Smartphone lacks a Tab key.) Each individual control has been modified to use the left and right cursor keys to provide navigation and selection within the control.
Scrolling Dialogs
Implementing a dialog box that scrolls is typically not an easy task. On the Smartphone, with its tiny screen, it's sometimes a necessity. Fortunately, the shell makes implementing scrolling dialogs fairly painless. All that is required is that the dialog box template have the WS_VSCROLL style flag set. When the user changes focus from control to control, if the next control is below the visible part of the screen, the shell scrolls the dialog automatically. If the focus is at the bottom most control and the user presses the Down cursor key, the Smartphone switches the focus back to the first control and scrolls the dialog back to the top.If the application repositions any of the controls on a scrolling dialog, it needs to tell the dialog manager about the new positions. This is done with the Smartphone unique message, DM_RESETSCROLL. If the controls are repositioned in the WM_INITDIALOG message or in any message before WM_INITDIALOG, sending DM_RESETSCROLL isn't required.