Partager via


How to Create a Spin Box Control

4/19/2010

You can create a spin box control for Windows Mobile Standard by using the Windows Embedded CE CreateWindow and Windows Embedded CE SendMessage functions.

To create a spin box control

  1. Add the CreateWindow function to create the list box control, and specify the control ID using the HMENU parameter. In the following code example, the HMENU parameter specifies nListID:

    hwndList = CreateWindow(TEXT("ListBox"), NULL, 
                            WS_VISIBLE | LBS_NOINTEGRALHEIGHT | 
                            NOT WS_BORDER,
                            x, y, cx, cy,
                            hwndParent, (HMENU)nListID, hinst, NULL);
    
  2. Add the CreateWindow function to create the up-down control. You can add styles to modify the control. For more information, see Spin Box Control.

    In the following code example, the UDS_SETBUDDYINT style is added to enable scrolling and the UDS_EXPANDABLE style is added to expand the control to a full screen when the user presses the Action key:

    hwndUpDown = CreateWindow(UPDOWN_CLASS, NULL, 
                              WS_VISIBLE | UDS_HORZ |UDS_ALIGNRIGHT | UDS_ARROWKEYS |  UDS_SETBUDDYINT | UDS_WRAP | UDS_EXPANDABLE, 
                              0, 0, 0, 0, 
                              hwndParent, (HMENU)nUpDownID, hinst, 
                              NULL);
    
  3. Add the SendMessage function to send a message to the up-down control. The message specifies the ID of the list box control and sets this control as the buddy window for the up-down control.

    In the parameter list, specify the up-down and list box control handles and the Windows Embedded CE UDM_SETBUDDY message. In the following code example, the handles are hwndUpDown and hwndList:

    SendMessage(hwndUpDown, UDM_SETBUDDY, (WPARAM)hwndList, 0);
    

Code Example

The following code example demonstrates how to create a spin box control.

Note

To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.

BOOL rb;
int rc;
LRESULT lr;

hwndList = CreateWindow(TEXT("ListBox"), NULL, 
                        WS_VISIBLE | LBS_NOINTEGRALHEIGHT, 
                        x, y, cx, cy,
                        hwndParent, (HMENU)nListID, hinst, NULL);

if (hwndList == NULL)  // CreateWindow failed.
{
    rc = MessageBox(NULL, _T("Could not create list box window."), _T("Error"), MB_OK);

    if (rc == 0)  // Not enough memory to create MessageBox.
        return E_OUTOFMEMORY;

    return E_FAIL;  // Replace with specific error handling.
}

hwndUpDown = CreateWindow(UPDOWN_CLASS, NULL, 
                          WS_VISIBLE | UDS_HORZ |UDS_ALIGNRIGHT | UDS_ARROWKEYS |  UDS_SETBUDDYINT | UDS_WRAP | UDS_EXPANDABLE, 
                          0, 0, 0, 0, 
                          hwndParent, (HMENU)nUpDownID, hinst, NULL);

if (hwndUpDown == NULL)  // CreateWindow failed.
{
    rc = MessageBox(NULL, _T("Could not create Up/Down window."), _T("Error"), MB_OK);

    if (rc == 0)  // Not enough memory to create MessageBox.
        return E_OUTOFMEMORY;

    return E_FAIL;  // Replace with specific error handling.
}

lr = SendMessage(hwndUpDown, UDM_SETBUDDY, (WPARAM)hwndList, 0);
// lr now contains the handle to the previous buddy window.

See Also

Concepts

Creating Windows Mobile Controls
Spin Box Control