Click here to Skip to main content
15,896,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai All

I am developing a MFC based SDI VC++ application. In my application I need to specify negative range value for my Slider Control. The minimum range for the Slider is -40 and maximum range is 255. I tried it using SetRange function. But it is not working. How can I set this range in the slider?Please Help..

My code for the Slider is as follows: Slider is declared as

C++
CSliderCtrl m_ctrlECTSlider;

OnInitialUpdate function contains

m_ctrlECTSlider.SetRangeMin(-40);
int iValMin = m_ctrlECTSlider.GetRangeMin();
m_ctrlECTSlider.SetRangeMax(255);
int iValMax = m_ctrlECTSlider.GetRangeMax();

m_ctrlECTSlider.SetPos(0);
SetDlgItemInt( IDC_ECT_VALUE, m_ctrlECTSlider.GetPos(), FALSE);
SetDlgItemInt( IDC_MIN_ECT, iValMin, FALSE);
SetDlgItemInt( IDC_MAX_ECT, iValMax, FALSE);

OnBnClickedSet function contains

int nMin = GetDlgItemInt(IDC_MIN_ECT, 0, FALSE);
int nMax = GetDlgItemInt(IDC_MAX_ECT, 0, FALSE);

m_ctrlECTSlider.SetRange(nMin, nMax);
m_ctrlECTSlider.SetPos(nMin);

int pos = m_ctrlECTSlider.GetPos();
SetDlgItemInt(IDC_ECT_VALUE, m_ctrlECTSlider.GetPos(), FALSE);      
m_ctrlECTSlider.RedrawWindow();


Here the problem is the value returned during debugg is all correct. But when it comes to UI on running the min value is 429496 and not -40 in the edit box..Why is it so..I am developing SDI application using CFormView class..

Thanks in advance.
Posted
Updated 6-Oct-13 22:36pm
v2
Comments
Richard MacCutchan 7-Oct-13 6:48am    
It sounds like you are displaying the value in the textbox without taking account of its sign.
Lekshmi KR 8-Oct-13 0:12am    
How to specify sign for the value?? I need that. The negative value should be specified in the textbox. How to do that??

Lekshmi KR 8-Oct-13 6:14am    
Ok got it..Thanks :-)
Its the bool value in SetDlgItemInt. I had to set it to TRUE. But unfortunately i set that to FALSE. That was my mistake. Thank you soo much
Richard MacCutchan 8-Oct-13 6:28am    
Yes, rather a non-intuitive function from Microsoft.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900