Solved

Intercepting Spin Control

Posted on 1998-09-22
7
531 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

623 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