Reputation: 97
I have a derived MFC CFormView
class (CMyFormView
) and I must implement my own OnVScroll
function.
My CMyFormView
is used for several dialog box resources, mainly, to re-implement the OnCtlColor()
function. Some dialogs contain a CSpinButtonCtrl
control.
My problem:
When the OnVScroll
function is invoked, I am unable to know if the Windows message comes from a CSpinButtonCtrl
or from the scrollbar.
void CMyFormView :: OnVScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar)
{
// message comes from CSpinButtonCtrl or VscrollBare ?
}
I cannot use the CSpinButtonCtrl
IDs (dlgitem) of the controls because they are very numerous.
Question:
How to know if the message comes from a CSpinButtonCtrl
or the scrollbar?
Environment details:
Upvotes: 1
Views: 309
Reputation: 51825
If the OnVScroll
handler is called via actions in a window's (framework-provided) scrollbar, then the pScrollBar
parameter will be NULL
; if it is from a control, then it will not be NULL
. From the CWnd Documentation:
pScrollBar
If the scroll message came from a scroll-bar control, contains a pointer to the control. If the user clicked a window's scroll bar, this parameter is NULL. The pointer may be temporary and should not be stored for later use.
So, you can simply check for a NULL
value:
void CMyFormView :: OnVScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar)
{
if (!pScrollBar) {
// From window's scrollbar...
}
else {
// From a control...
}
}
Upvotes: 1