How to: Create a Spin Box Control

Code Example

You can create a spin box control for a Windows Mobile-based Smartphone by using the Windows CE CreateWindow and Windows 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, 
                            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(TEXT("UpDownClass"), 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 CE UDM_SETBUDDY message. In the following code example, the handles are hwndUpDown and hwndList:

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

Example

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(TEXT("UpDownClass"), 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

Spin Box Control

Windows Mobile Controls

Last updated on Friday, April 22, 2005

© 2005 Microsoft Corporation. All rights reserved.

Send feedback on this topic to the authors.