Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple winapi spin control

Tags:

c++

winapi

mfc

wtl

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
like image 947
AlexandruC Avatar asked Aug 03 '26 23:08

AlexandruC


2 Answers

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.

like image 143
Mark Ransom Avatar answered Aug 05 '26 12:08

Mark Ransom


In WTL you have wrapper class CUpDownCtrl for up-down control. So it goes as simple as this:

CUpDownCtrl Control = ... // e.g. GetDlgItem(IDC_MYCONTROL);
INT nMinValue = 0, nMaxValue = 100;
Control.SetRange(nMinValue, nMaxValue);
like image 26
Roman R. Avatar answered Aug 05 '26 13:08

Roman R.