Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting Up / Down arrows in CSpinButtonCtrl MFC C++

Tags:

spinner

mfc

Is there any way to differentiate when the Up or Down arrow of a CSpinButtonCtrl is pressed?

I am trying to use the OnPointerdown event, but I don't know how to do it...

afx_msg LRESULT CMySpinButtonCtrl::OnPointerdown(WPARAM wParam, LPARAM lParam)
{
   if(IS_POINTER_PRIMARY_WPARAM(wParam))
   {
       //TODO
   }
   return 0;
}

I will appreciate any kind of help.

like image 517
Alberto Bricio Avatar asked Dec 13 '22 17:12

Alberto Bricio


1 Answers

Is there any way to differentiate when the Up or Down arrow of a CSpinButtonCtrl is pressed?

You should use UDN_DELTAPOS to do this.

  • Right-click the control in the Resource Editor and select Add Event Handler:

Add Event Handler

  • Select the UDN_DELTAPOS message and click Add and Edit:

UDN_DELTAPOS

  • You will be provided with skeleton code:

    void CMFCApplication1Dlg::OnDeltaposSpin1(NMHDR *pNMHDR, LRESULT *pResult)
    {
        LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
        // TODO: Add your control notification handler code here
        *pResult = 0;
    }
    
  • The NMUPDOWN article explains about the structure that you use. What you need to do is test the iDelta value. Example:

    void CColumnOrderDlg::OnDeltaposSpinColumns(NMHDR* pNMHDR, LRESULT* pResult) 
    {
        LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
    
        if (pNMUpDown != nullptr)
        {
            if( pNMUpDown->iDelta > 0)
                // Up - Do stuff;
            else if(pNMUpDown->iDelta < 0)
                // Down - Do stuff;
        }
    
        *pResult = 0;
    }
    

There is also a useful article here where it states:

If you use a spin control for some other purpose, for example, to page through a sequence of windows or dialog boxes, then add a handler for the UDN_DELTAPOS message and perform your custom action there.

like image 51
Andrew Truckle Avatar answered May 12 '23 06:05

Andrew Truckle