A CSliderCtrl
wraps a trackbar control. As such, the former shares the same limitations with the latter. Specifically, the range is set through the TBM_SETRANGE
message (or the TBM_SETRANGEMIN
and TBM_SETRANGEMAX
messages). Either message takes an integral value, so you cannot have the control operate on fractional values.
If you need the integral values supported by the control to represent fractional values, you will have to perform the mapping in client code (scaling and translation). Possible mappings are:
- Set the range from
0 * 4
to(100 - 14) * 4
(i.e.0
to344
). The control positionx
represents the value14 + x / 4
. - Set the range from
14 * 4
to100 * 4
(i.e.56
to400
). The control positionx
then represents the valuex / 4
.
In general, fractional values cannot accurately be represented when using floating point values. In this case, however, there is no loss in accuracy; any integer value divided by a power-of-two (such as 4) can be accurately represented by a floating point value (so long as the result is still in range).
CLICK HERE to find out more related problems solutions.