Solved

Intercepting Spin Control

Posted on 1998-09-22
7
514 Views
Last Modified: 2009-07-29
I have a ten spin controls. One has a text value 12.2 written in it. I want to be able to press up arrow and intercept this (because if I do not, the value resets to the minimum value) and increment this to 13. Someone gave me help with this earlier but I can't seem to get this right. Something about using WM_VSCROLL and then catching the message. What message comes for each spin up arrow? How do I manipulate it? Etc? Thanks!
0
Comment
Question by:rose3377
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Expert Comment

by:jrmcg
ID: 1173369
Rose, I would suggest posting a 0 point question to whoever the Expert was that helped you originally.  If there was something that you didn't understand then ask him/her to explain it to you further.  There is no sense in wasting points on a question you have already asked and given points for.  I'm sure whoever it was would be more than happy to help.  If that doesn't work, I can walk you through it.

Best Regards,  J.R.

If you plan on doing what I suggested, delete this question before it is locked.


0
 
LVL 2

Expert Comment

by:jrmcg
ID: 1173370
I noticed in your history that you haven't asked a similar question.  If it was not an expert from EE that helped you previously, then I will be more than happy to answer your question for you.
0
 

Author Comment

by:rose3377
ID: 1173371
Hi JRMCG... I previously asked the question under my friends account (co-incidently called rose337) and got an answer from sanj. Anyway, I don't want to bother my friend again so if you don't mind, may I bother you ;-) Thanks for any help.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:sunj
ID: 1173372
Hi rose3377!

  Sorry for the delay :-) I am putting this as a comment. After your program works, you can adjust the point to be zero and I will then post it again as answer so that it's fair to you.

  Anyway, here comes the details(assuming you are using MFC):

  Assume you have a spin control with ID called IDC_SPIN1
  In your OnInitDialog(), add the following:
------------------------------------------------------------
      CSpinButtonCtrl* pSpin =
            (CSpinButtonCtrl*) GetDlgItem(IDC_SPIN1);
      pSpin->SetRange(0, 100);
      pSpin->SetPos((int) (m_dSpin * 10.0));
------------------------------------------------------------

  Then add a windows message handler to the map the WM_VSCROLL message that the spin control sends to the dialog. Here's the code:

------------------------------------------------------------
void CEx06bDialog::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
      if (nSBCode == SB_ENDSCROLL) {
            return; // Reject spurious messages
      }
      // Process scroll messages from IDC_SPIN1 only
      if (pScrollBar->GetDlgCtrlID() == IDC_SPIN1) {
            CString strValue;
            strValue.Format("%3.1f", (double) nPos / 10.0);
            ((CSpinButtonCtrl*) pScrollBar)->GetBuddy()
                                           ->SetWindowText(strValue);
      }
}
-----------------------------------------------------------------

And that's it! You can set the spin range to suit your needs.

Let me know.

sunj
0
 

Author Comment

by:rose3377
ID: 1173373
Thanks SANJ !!! Perfect ;-)
0
 

Author Comment

by:rose3377
ID: 1173374
PS Submit the answer and take the points... I insist ;-)
0
 
LVL 1

Accepted Solution

by:
sunj earned 70 total points
ID: 1173375
Thanks, rose3377. I am now re-submitting it as answer...


  Assume you have a spin control with ID called IDC_SPIN1
  In your OnInitDialog(), add the following:
------------------------------------------------------------
CSpinButtonCtrl* pSpin =
(CSpinButtonCtrl*) GetDlgItem(IDC_SPIN1);
pSpin->SetRange(0, 100);
pSpin->SetPos((int) (m_dSpin * 10.0));
------------------------------------------------------------

  Then add a windows message handler to the map the WM_VSCROLL message that the spin control sends to the dialog. Here's the code:

------------------------------------------------------------
void CEx06bDialog::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if (nSBCode == SB_ENDSCROLL) {
return; // Reject spurious messages
}
// Process scroll messages from IDC_SPIN1 only
if (pScrollBar->GetDlgCtrlID() == IDC_SPIN1) {
CString strValue;
strValue.Format("%3.1f", (double) nPos / 10.0);
((CSpinButtonCtrl*) pScrollBar)->GetBuddy()
                               ->SetWindowText(strValue);
}
}
-----------------------------------------------------------------
sunj
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AVI wait icons for CAnimateCtrl in Visual Studio 2008 MFC 1 159
C++ question 3 74
Best book to learn C++ 4 87
Beginner to Unreal Engine 4 5 104
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

680 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