Solved

SpinButton with multiple ranges

Posted on 1998-07-30
5
210 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:joeslow
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:psdavis
ID: 1319985
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
 
LVL 6

Expert Comment

by:snoegler
ID: 1319986
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
 
LVL 7

Expert Comment

by:psdavis
ID: 1319987
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
 

Author Comment

by:joeslow
ID: 1319988
Snoegler's answer is what I was looking for...
Resend me a dummy message for the points
0
 
LVL 6

Accepted Solution

by:
snoegler earned 100 total points
ID: 1319989
Phillip, many thanks ...
So that's something i can't reject  ;)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now