Search code examples
c++winapimfcwtl

simple winapi spin control


I am trying to make a simple spin control and edit box in WTL &/ winapi. and this does not work properly, because I only see 0 as initial value and the arrows don t work, code here:

HWND spin = GetDlgItem(IDC_SPIN1);
HWND edit = GetDlgItem(IDC_RANDOM_EDIT);
::SendMessage(spin, UDM_SETBUDDY, (WPARAM)edit, 0); //set buddy
::SendMessage(spin, UDM_SETRANGE, MAKELPARAM(0,100), 0); //interval

::SendMessage(spin, UDM_SETBASE, 10, 0); //initial position

Solution

  • You have your wparam and lparam reversed. You also have the low and high words reversed.

    ::SendMessage(spin, UDM_SETRANGE, 0, MAKELPARAM(100,0)); //interval
    

    See the definitions of UDM_SETRANGE and MAKELPARAM.