Solved

Intercepting Spin Control

Posted on 1998-09-22
7
509 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

839 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