HomeC&C++WainTutorialsSamplesTip&TrickTools


We will add a Up-Down Spin to the edit boxes.
This will create two small arrow buttons on the right side of the edit box, which the user can use to increase or decrease the value in the edit box.
As usual we a control is a window, so we use CreateWindow to create the control:
      CreateWindow(UPDOWN_CLASS,
                   "Spin1",
                   UDS_AUTOBUDDY | UDS_ALIGNRIGHT |
                   UDS_SETBUDDYINT | WS_CHILD | WS_VISIBLE |
                   UDS_ARROWKEYS,
                   105, 5, 20, 20,
                   hwndDlg,
                   (HMENU )FirstUpDownId,
                   InstanceHandle,
                   0);
No surprise here. UPDOWN_CLASS is the name for an predefined wnd-class for updown controls.
We will then set the range, that is the min and max value, for the control. Default min value is 100 and max 0, so it will by default scrool the wrong way.
To set the range:
SendDlgItemMessage(hwndDlg,
                   FirstUpDownId,
                   UDM_SETRANGE,
                   0,
                   MAKELONG(100, -100));
This will enable the spin to spin in the range from -100 to 100.
This is all we have to do.
To use the up-down contol you have to include commctrl.h, call InitCommonControls and link with comctl32.lib.
The complete code for the application can be found here.