Creating an Up-Down Control

An up-down control is a pair of arrow buttons that a user can tap with the stylus to increment or decrement a value. An up-down control may be used in one of two ways: as a stand-alone control or in conjunction with another control, called a buddy window. In Windows CE–based applications, up-down controls can be paired only with edit controls. When an up-down control is paired with an edit control, it is called a spin control. The following screen shot shows an up-down control and buddy window.

You create an up-down control by using the CreateUpDownControl function. This class is registered when the common control DLL is loaded. You can use the InitCommonControls function to ensure that this DLL is loaded.

To register the up-down control class using the InitCommonControlsEx function, specify the ICC_UPDOWN_CLASS flag as the dwICC member of the INITCOMMONCONTROLSEX structure you pass in the lpInitCtrls parameter.

The following code example is the syntax for the CreateUpDownControl function.

HWND CreateUpDownControl (DWORD dwStyle,   
                          int x,   
                          int y,   
                          int cx,   
                          int cy,   
                          HWND hParent,   
                          int nID,   
                          HINSTANCE hInst,  
                          HWND hBuddy,   
                          int nUpper,   
                          int nLower,   
                          int nPos);

Here, dwStyle specifies the style of the up-down control. You must include the WS_CHILD, WS_BORDER, and WS_VISIBLE styles, and it may include any of the window styles specific to the up-down control. For a complete listing of supported styles, see Window and Control Styles.

The upper-left corner of a control is positioned at coordinates x, y, and its dimension is determined by the values cx and cy. The handle to the parent window is passed in hParent and the control identifier is specified in nID. The handle to the application is passed in hInst. The handle to the buddy window is passed in hBuddy. If there is no buddy window, this parameter must be NULL.

The upper-limit range of the control is passed in nUpper and the lower-limit range is passed in nLower. The initial position of the control is specified in nPos. This value must be within the specified range.