CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2000
    Location
    Washington (state)
    Posts
    125

    Spin Control Notification

    I have a spin control for which I need to execute a particular function AFTER the user has released the button (up or down) on the spin control... that is, I do not want to do this function for each iteration of the spin control... ONLY when the spin control has stopped incrementing. The only message handlers I see that are offered by the MFC ClassWizard are NM_OUTOFMEMORY and UDN_DELTAPOS. Neither of these seems to be what I need.

    How can I know that the spin control has changed its buddy CEdit control AND that the spin control is not continuing to increment?

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244
    If you are from Washington (state), take a run to Redmond WA and ask the MS fellows.
    Now serious...
    After sending UDN_DELTAPOS (in that the position is not changed yet), a WM_VSCROLL or WM_HSCROLL is also sent.
    See the example below. I hope this solves your problem.
    Code:
    void CADialog::OnDeltaposSpin1(NMHDR* pNMHDR, LRESULT* pResult) 
    {
       NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
       // the position is not changed yet, so
       // keep in mind the old position
       m_iPos = pNMUpDown->iPos;
    	
       *pResult = 0;
    }
    void CADialog::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
    {
       if(pScrollBar->m_hWnd == m_spin.m_hWnd)
       {
          if(SB_THUMBPOSITION == nSBCode)
          {
             if( m_iPos == nPos )
             {
                // the position was not changed, so...
                AfxMessageBox( _T("Bau!!!") );
                return;
             }
          }
       }
       CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
    }
    Last edited by ovidiucucu; March 31st, 2004 at 11:38 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    Join Date
    Apr 2000
    Location
    Washington (state)
    Posts
    125
    Thanks ! I will give this a try...

  4. #4
    Join Date
    Apr 2000
    Location
    Washington (state)
    Posts
    125

    Thumbs up

    THANKS ovidiucucu !

    With one minor change, this does exactly what I need.

    I had to change

    if(SB_THUMBPOSITION == nSBCode)

    to

    if(SB_ENDSCROLL == nSBCode)

  5. #5
    Join Date
    Oct 2009
    Posts
    17

    Re: Spin Control Notification

    Sford or Ovidiucucu:
    I'm trying to do the same thing in VC++6, but till now i can't , Ovidiucucu you said that after sending UDN_DELTAPOS a WM_VSCROLL or WM_VSCROLL is sent , so for spin control (not scroll bar) WM_VSCROLL and WM_VSCROLL are sent too? .Only to see if this is happening in my app ,i wrote:
    Code:
    void CADialog::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
    {
       
                // the position was not changed, so...
                AfxMessageBox( _T("Bau!!!") );
                return;
       CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
    }
    i think that with this every time the i touch de spin, the message box should apperas, but it doesn't. The code compiles with no erros.
    What is wrong ?

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Spin Control Notification

    Quote Originally Posted by Timbk View Post
    Sford or Ovidiucucu:
    I'm trying to do the same thing in VC++6, but till now i can't , Ovidiucucu you said that after sending UDN_DELTAPOS a WM_VSCROLL or WM_VSCROLL is sent , so for spin control (not scroll bar) WM_VSCROLL and WM_VSCROLL are sent too? .Only to see if this is happening in my app ,i wrote:
    Code:
    void CADialog::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
    {
       
                // the position was not changed, so...
                AfxMessageBox( _T("Bau!!!") );
                return;
       CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
    }
    i think that with this every time the i touch de spin, the message box should apperas, but it doesn't. The code compiles with no erros.
    What is wrong ?
    Did you create the corresponding message map entry for OnVScroll?

  7. #7
    Join Date
    Oct 2009
    Posts
    17

    Re: Spin Control Notification

    Nice, the message map entry was wrong , now works nicely. 1 day to solve this , anyway this is how it looks now
    header file
    Code:
    afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
    Source file
    Message map
    Code:
    ON_WM_VSCROLL()
    And handler
    Code:
    void CCalibracionDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
    {
      if(SB_ENDSCROLL == nSBCode)
      {
          if(pScrollBar->m_hWnd == m_Spin1m_hWnd)
          {
                // the position was not changed, so...
                AfxMessageBox( _T("Termino el Spin1!!!") );
                return;
          }
          if(pScrollBar->m_hWnd == m_Spin2.m_hWnd)
          {
                // the position was not changed, so...
                AfxMessageBox( _T("Termino el Spin2!!!") );
                return;
          }
      }
    }
    Thanks Arjay, where are you from?

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Spin Control Notification

    Quote Originally Posted by Timbk View Post
    Thanks Arjay, where are you from?
    ...from a galaxy far, far away.

  9. #9
    Join Date
    Oct 2009
    Posts
    17

    Re: Spin Control Notification

    Quote Originally Posted by Arjay View Post
    ...from a galaxy far, far away.
    incredible, even that, your posts come so fast !!!

  10. #10
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Spin Control Notification

    I live in Bellevue, WA - close to Seattle. When I moved there I traded in my light saber for a high speed internet connection.

  11. #11
    Join Date
    Oct 2009
    Posts
    17

    Re: Spin Control Notification

    Jejejej , i thought that, well thanks again, and May the Force be with you, oh no no i have to say May the speed be with you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured