From: Tony on 28 Oct 2009 11:53 Hi I have a CSliderCtrl configured with a min value of 0 and a max value of 16, set using SetRange(0, 16); I have a tic frequency set to 8 so that I get my lines nicely positioned, using SetTicFreq(Range / StepSize); My step size is set to 2. My problem is that when I use my left and right arrow keys the increment / decrement is 2, but when I use the mouse I can increment / decrement in 1's. I want the increment / decrement to be in 2s. The code is as follows CSliderCtrl *pSC = (CSliderCtrl *)GetDlgItem(IDC_SLIDER_VALUE); ASSERT( pSC ); if( pSC && iStep != 0 && iMax >= iMin ) { // Set up the scroll bar pSC->SetRange( iMin, iMax ); pSC->SetLineSize( iStep ); pSC->SetPos( iVal ); // Do tick mark calculations int iNumberTicks = (iMax - iMin)/iStep; int iDelta = iStep; while( iNumberTicks > 50 ) { iStep += iDelta; iNumberTicks = (iMax - iMin)/iStep; } pSC->SetTicFreq( iStep ); } Can anyone tell me what is wrong? TIA Tony
From: David Ching on 28 Oct 2009 18:37 "Tony" <tony(a)home.com> wrote in message news:OQasbb#VKHA.1232(a)TK2MSFTNGP05.phx.gbl... > Hi > > I have a CSliderCtrl configured with a min value of 0 and a max value of > 16, set using SetRange(0, 16); > I have a tic frequency set to 8 so that I get my lines nicely positioned, > using SetTicFreq(Range / StepSize); > > My step size is set to 2. > > My problem is that when I use my left and right arrow keys the increment / > decrement is 2, but when I use the mouse I can increment / decrement in > 1's. I want the increment / decrement to be in 2s. > > The code is as follows > > CSliderCtrl *pSC = (CSliderCtrl *)GetDlgItem(IDC_SLIDER_VALUE); > ASSERT( pSC ); > if( pSC && iStep != 0 && iMax >= iMin ) > { > // Set up the scroll bar > pSC->SetRange( iMin, iMax ); > pSC->SetLineSize( iStep ); > pSC->SetPos( iVal ); > // Do tick mark calculations > int iNumberTicks = (iMax - iMin)/iStep; > int iDelta = iStep; > while( iNumberTicks > 50 ) > { > iStep += iDelta; > iNumberTicks = (iMax - iMin)/iStep; > } > pSC->SetTicFreq( iStep ); > } > Since you SetLineSize(2), getting movement of 2 for each arrow press is exactly what is supposed to happen. From MSDN: "The line size affects how much the slider moves for the TB_LINEUP and TB_LINEDOWN notifications." (Since this is a horizontal slider, up/down really means "left/right"). -- David
From: Joseph M. Newcomer on 28 Oct 2009 19:03 See below... On Wed, 28 Oct 2009 15:53:58 -0000, "Tony" <tony(a)home.com> wrote: >Hi > >I have a CSliderCtrl configured with a min value of 0 and a max value of 16, >set using SetRange(0, 16); >I have a tic frequency set to 8 so that I get my lines nicely positioned, >using SetTicFreq(Range / StepSize); > >My step size is set to 2. > >My problem is that when I use my left and right arrow keys the increment / >decrement is 2, but when I use the mouse I can increment / decrement in 1's. >I want the increment / decrement to be in 2s. > >The code is as follows > >CSliderCtrl *pSC = (CSliderCtrl *)GetDlgItem(IDC_SLIDER_VALUE); >ASSERT( pSC ); **** The above code is silly. Create a control variable and use it. If you are writing more than one GetDlgItem per year, you are probably not using MFC correctly. You should assume that writing GetDlgItem, except in rare and exotic circumstances, is always a programming error. This is not a rare or exotic circumstance, it its use is contraindicated. **** >if( pSC && iStep != 0 && iMax >= iMin ) >{ > // Set up the scroll bar > pSC->SetRange( iMin, iMax ); > pSC->SetLineSize( iStep ); > pSC->SetPos( iVal ); > // Do tick mark calculations > int iNumberTicks = (iMax - iMin)/iStep; > int iDelta = iStep; > while( iNumberTicks > 50 ) > { > iStep += iDelta; > iNumberTicks = (iMax - iMin)/iStep; > } > pSC->SetTicFreq( iStep ); >} > **** None of these have much to do with how the mouse works. THe mouse can always work in increments of 1 unit. If you want the mouse and keyboard to both move in elements of 2 units, then you would set the range for half of the desired range and multiply everything by 2. joe **** >Can anyone tell me what is wrong? > >TIA > >Tony > > Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
|
Pages: 1 Prev: CStatusBar Feature Need You Help. Next: CMFCStatusBar pane text |