Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Intercepting Spin Control

Posted on 1998-09-22
7
Medium Priority
?
546 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 280 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

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!

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.

704 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