How to get numeric updown control?

Viewed 167

I have searched in toolbox and many post but don't know where to find this type of control to use on MFC:

Numerictextbox

Does such a control exist in MFC?

1 Answers

The control is known as a "Spin Control" in the Visual Studio Resource editor and they are normally associated with a "Buddy" edit control. You can set this in the "Behaviour" group of its "Properties" window – with "Auto Buddy" set to "True", it will associate with the 'nearest' edit control (actually, the previous control in the Z-order). You will probably also want to have "Set Buddy Integer" set to "True".

enter image description here

There are numerous routines associated with such controls (such as those to set/get the range and position), and the behaviour is encapsulated in the CSpinButtonCtrl class, for which there is a good overview here.


If you prefer to manually edit/create your resource scripts, then you'll need a control of the msctls_updown32 class, which should be added immediately following the buddy edit window, as in the following code excerpt:

IDP_OPTMD   DIALOGEX    0, 0, 262, 180
STYLE       WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_CAPTION
CAPTION     L"Dilation/Skeletonisation"
FONT        10, P_GUIFONT
{
    GROUPBOX        L"Pixel Dilation Options",      IDC_DILPG,   10,  6, 247, 99,   BS_GROUPBOX | SS_NOTIFY
    AUTOCHECKBOX    L"Enable advanced options dialogue box?",   IDC_DILEO,   17, 17, 160, 11,   BS_AUTOCHECKBOX
    LTEXT           L"Cycles =",                    IDC_DCYCS|0x8000,   190, 18, 30, 11,        SS_NOTIFY
    EDITTEXT        IDC_DCYCS,                      221, 17, 28, 12,    ES_CENTER | ES_NUMBER,  WS_EX_CLIENTEDGE
    CONTROL         1,  IDC_DCYUD,  L"msctls_updown32", UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY |UDS_ARROWKEYS
                    | UDS_NOTHOUSANDS,  241, 17, 12, 10
    //...
Related