MFC - Spin Button
A Spin Button Control (also known as an up-down control) is a pair of arrow buttons that the user can click to increment or decrement a value, such as a scroll position or a number displayed in a companion control. it is represented by CSpinButtonCtrl class.
Here is the list of methods in CSpinButtonCtrl class −
Sr.No. | Name & Description |
---|---|
1 | Create Creates a spin button control and attaches it to a CSpinButtonCtrl object. |
2 | CreateEx Creates a spin button control with the specified Windows extended styles and attaches it to a CSpinButtonCtrl object. |
3 | GetAccel Retrieves acceleration information for a spin button control. |
4 | GetBase Retrieves the current base for a spin button control. |
5 | GetBuddy Retrieves a pointer to the current buddy window. |
6 | GetPos Retrieves the current position of a spin button control. |
7 | GetRange Retrieves the upper and lower limits (range) for a spin button control. |
8 | SetAccel Sets the acceleration for a spin button control. |
9 | SetBase Sets the base for a spin button control. |
10 | SetBuddy Sets the buddy window for a spin button control. |
11 | SetPos Sets the current position for the control. |
12 | SetRange Sets the upper and lower limits (range) for a spin button control. |
Here is the list of messages mapping for Spin Button control.
Message | Map entry | Description |
---|---|---|
BN_CLICKED | ON_BN_CLICKED( <id>, <memberFxn> ) | The framework calls this member function when is button clicked. |
BN_DISABLE | ON_BN_DISABLE( <id>, <memberFxn> ) | The framework calls this member function when button is disabled. |
BN_DOUBLECLICKED | ON_BN_DOUBLECLICKED( <id>, <memberFxn> ) | The framework calls this member function when button is double clicked. |
BN_PAINT | ON_BN_PAINT( <id>, <memberFxn> ) | The framework calls this member function when an application makes a request to repaint a button. |
Let us look into a simple example of Spin button by creating a new MFC dialog based application.
Step 1 − Add one Spin Control and one Edit control from the Toolbox.
Step 2 − Go to the Properties of Spin Control and set the values of Auto Buddy and Set Buddy Integer to True.