Solved

Intercepting Spin Control

Posted on 1998-09-22
7
491 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 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

20 Experts available now in Live!

Get 1:1 Help Now