Notifiation Messages for CSpinButtonCtrl in MFC
-
Hi I created a control in my MFC application as follows:
CSpinButtonCtrl m_spin;
m_spin.Create(UDS_HORZ, CRect(0, 0, 50, 50), this, 1011);
m_spin.ShowWindow(1);which created a spin control with two button with left arrow and right arrow. Now i want to perform some job based on the user clicks on these two buttons. I tried by adding notification message in Message map as follows:
ON_NOTIFY(NM_CLICK, IDC_SPIN1, OnDropDown)
The above message dint called my OnDropDown(). I tried adding ON_WM_HSCROLL(), it worked. The function OnHScroll is getting executed when i click on right or left arrow buttons in spin control. But what my fear is, in near future i may also add a scroll bars (horiz and veritcal) in my application. That time this may get conflict with my spin control. So, i am looking for a message which will notify me when left or arrow arrow is invoked on spin control.
-
Hi I created a control in my MFC application as follows:
CSpinButtonCtrl m_spin;
m_spin.Create(UDS_HORZ, CRect(0, 0, 50, 50), this, 1011);
m_spin.ShowWindow(1);which created a spin control with two button with left arrow and right arrow. Now i want to perform some job based on the user clicks on these two buttons. I tried by adding notification message in Message map as follows:
ON_NOTIFY(NM_CLICK, IDC_SPIN1, OnDropDown)
The above message dint called my OnDropDown(). I tried adding ON_WM_HSCROLL(), it worked. The function OnHScroll is getting executed when i click on right or left arrow buttons in spin control. But what my fear is, in near future i may also add a scroll bars (horiz and veritcal) in my application. That time this may get conflict with my spin control. So, i am looking for a message which will notify me when left or arrow arrow is invoked on spin control.
The notification message send to the parent uses the UDN_DELTAPOS notification code (Windows)[^]
-
Hi I created a control in my MFC application as follows:
CSpinButtonCtrl m_spin;
m_spin.Create(UDS_HORZ, CRect(0, 0, 50, 50), this, 1011);
m_spin.ShowWindow(1);which created a spin control with two button with left arrow and right arrow. Now i want to perform some job based on the user clicks on these two buttons. I tried by adding notification message in Message map as follows:
ON_NOTIFY(NM_CLICK, IDC_SPIN1, OnDropDown)
The above message dint called my OnDropDown(). I tried adding ON_WM_HSCROLL(), it worked. The function OnHScroll is getting executed when i click on right or left arrow buttons in spin control. But what my fear is, in near future i may also add a scroll bars (horiz and veritcal) in my application. That time this may get conflict with my spin control. So, i am looking for a message which will notify me when left or arrow arrow is invoked on spin control.
For spin button control you can use the [UDN_DELTAPOS notification code (Windows)](https://msdn.microsoft.com/en-us/library/windows/desktop/bb759903(v=vs.85).aspx)
-
The notification message send to the parent uses the UDN_DELTAPOS notification code (Windows)[^]
Sorry i tried this as follows
ON_NOTIFY_REFLECT(UDN_DELTAPOS,OnSpinContol)
Its throws syntax error and could not find any sample in google to declare the message.
-
Sorry i tried this as follows
ON_NOTIFY_REFLECT(UDN_DELTAPOS,OnSpinContol)
Its throws syntax error and could not find any sample in google to declare the message.
In what class did you implement it? Please, post the exact code snippets!
-
Sorry i tried this as follows
ON_NOTIFY_REFLECT(UDN_DELTAPOS,OnSpinContol)
Its throws syntax error and could not find any sample in google to declare the message.
That is for handling the message by the control class itself when having it derived. To handle the message in the parent do it like you have done already:
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN1, OnDeltaPos)
-
In what class did you implement it? Please, post the exact code snippets!
BEGIN_MESSAGE_MAP(CMyClass, CScrollView)
ON_NOTIFY_REFLECT(UDN_DELTAPOS,OnSpinContol)
END_MESSAGE_MAP()void CMyClass::OnSpinContol(NMHDR *pNMHDR, LRESULT *pResult)
{}
-
That is for handling the message by the control class itself when having it derived. To handle the message in the parent do it like you have done already:
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN1, OnDeltaPos)
Even tried below one, but no luck. :(
BEGIN_MESSAGE_MAP(CMyClass, CScrollView)
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN, OnSpinContol)
END_MESSAGE_MAP()void CMyClass::OnSpinContol(NMHDR *pNMHDR, LRESULT *pResult)
{}
-
BEGIN_MESSAGE_MAP(CMyClass, CScrollView)
ON_NOTIFY_REFLECT(UDN_DELTAPOS,OnSpinContol)
END_MESSAGE_MAP()void CMyClass::OnSpinContol(NMHDR *pNMHDR, LRESULT *pResult)
{}
CMyClass seems to be a parent/owner of the spin control. So there must be ON_NOTIFY macro, not a ON_NOTIFY_REFLECT
-
Even tried below one, but no luck. :(
BEGIN_MESSAGE_MAP(CMyClass, CScrollView)
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN, OnSpinContol)
END_MESSAGE_MAP()void CMyClass::OnSpinContol(NMHDR *pNMHDR, LRESULT *pResult)
{}
Sampath579 wrote:
Even tried below one, but no luck. :(
BEGIN_MESSAGE_MAP(CMyClass, CScrollView)
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN, OnSpinContol)
END_MESSAGE_MAP()void CMyClass::OnSpinContol(NMHDR *pNMHDR, LRESULT *pResult)
{}
1. Define "no luck". 2. Do you pass the correct control ID (IDC_SPIN)?
-
Even tried below one, but no luck. :(
BEGIN_MESSAGE_MAP(CMyClass, CScrollView)
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN, OnSpinContol)
END_MESSAGE_MAP()void CMyClass::OnSpinContol(NMHDR *pNMHDR, LRESULT *pResult)
{}
It is very probably sourced by the creation of your spin control:
m_spin.Create(UDS_HORZ, CRect(0, 0, 50, 50), this, 1011);
That misses the common window style flags like
WS_CHILD | WS_VISIBLE | WS_TABSTOP
. Just out of interest: Why are you creating your controls manually instead of using resource templates? With templates the default settings are initially set in the resource editor so that such errors did not occur. -
It is very probably sourced by the creation of your spin control:
m_spin.Create(UDS_HORZ, CRect(0, 0, 50, 50), this, 1011);
That misses the common window style flags like
WS_CHILD | WS_VISIBLE | WS_TABSTOP
. Just out of interest: Why are you creating your controls manually instead of using resource templates? With templates the default settings are initially set in the resource editor so that such errors did not occur.Hey Thanks.. Finally its working. The very first thing is i am new to MFC and second is i am creating all dynamic windows and controls based on user input.
-
Sampath579 wrote:
Even tried below one, but no luck. :(
BEGIN_MESSAGE_MAP(CMyClass, CScrollView)
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN, OnSpinContol)
END_MESSAGE_MAP()void CMyClass::OnSpinContol(NMHDR *pNMHDR, LRESULT *pResult)
{}
1. Define "no luck". 2. Do you pass the correct control ID (IDC_SPIN)?
Hey Thanks Victor. Its working now.