SpinButton with multiple ranges

What would be a good way to have multiple ranges associated to one CSpinButtonCtrl.  For example, say I want the valid value of something to be 1-100 and 150-300 and 305.  So when the user was spinning up the numbers would be 1, 2, 3...98, 99, 100, 150, 151...299, 300, 305
joeslowAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
snoeglerConnect With a Mentor Commented:
Phillip, many thanks ...
So that's something i can't reject  ;)
0
 
psdavisCommented:
You should be able to override the OnRotateControl function to customize the spin button to do whatever numbering that you would want.

void CRotationCtrl::OnRotateControl(NMHDR* pNMHDR, LRESULT* pResult)
{
   NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;

// TODO: Add your control notification handler code here

   m_sRotatedAngle += -( pNMUpDown->iDelta * 10 );
   ... Whatever...

}

0
 
snoeglerCommented:
Hello

psdavis, while i have written this you sent already an answer :(
but i think i'll post it though, don't take this as an affront.
In the dialog or window containing the spin button, invoke ClassWizard. Select your spin-
button control, and create a function for the notification UDN_DELTAPOS(which is sent before
the spin button will display an altered value). Then ClassWizard
will generate a function like CMyDialog::OnDeltaposMySpinButton(...).
ClassWizard will generate a NM_UPDOWN structure from the parameters which makes the
handling easier(for a more detailed info, see UDN_DELTAPOS in the online help).
It has among others the elements iPos and iDelta ( ==> iPos+iDelta= new position). With those
you can check if the next change will result in a range which you do not want to have - all you
have to do now is to set iDelta to a value so that iPos+iDelta jump around the range.

void CMyDialog::OnDeltaposMySpinButton( ... )
{
  NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  // TODO: Add your control notification handler code here

  int proposed=(pNMUpDown->iPos+pNMUpDown->iDelta);
  int shouldbe=proposed;
  BOOL increasing=(pNMUpDown->iDelta>0);
  if(proposed>=20 && proposed<40) {
    if(increasing)
      shouldbe=40;
    else
      shouldbe=20;
  }
  if(proposed>=60 && proposed<80) {
    if(increasing)
      shouldbe=80;
    else
      shouldbe=60;
  }
  pNMUpDown->iDelta=shouldbe-pNMUpDown->iPos;

  *pResult = 0;
}

I hope this one helps you
0
 
psdavisCommented:
Snoegler,

Definitely a better and more complete answer than I gave.  Don't feel bad about it.  These points are absolutely worthless anyway :).

JoeSlow,

If snoegler's answer gives you everything you need, go ahead and reject my answer and ask him to resend a dummy message for the points.

Phillip

0
 
joeslowAuthor Commented:
Snoegler's answer is what I was looking for...
Resend me a dummy message for the points
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.